erfanzar commited on
Commit
434e91c
1 Parent(s): 8dc863f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -0
README.md CHANGED
@@ -32,6 +32,55 @@ Q&A: USER: how can i start to workout more \n
32
  INFO: USER: how can i start to workout more \n
33
  ```
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # Using Model in OST
36
 
37
 
 
32
  INFO: USER: how can i start to workout more \n
33
  ```
34
 
35
+ ```python
36
+ from transformers import LlamaTokenizer, LlamaForCausalLM, pipeline
37
+ import torch
38
+ import textwrap
39
+ tokenizer = LlamaTokenizer.from_pretrained("erfanzar/LGeM-7B-MT")
40
+
41
+ model = LlamaForCausalLM.from_pretrained(
42
+ 'erfanzar/LGeM-7B-MT',
43
+ load_in_8bit=True,
44
+ device_map='auto',
45
+ torch_dtype=torch.float16,
46
+ )
47
+
48
+ pipe_line = pipeline(
49
+ "text-generation",
50
+ model=model,
51
+ tokenizer=tokenizer,
52
+ max_length=256, # Your max length here
53
+ temperature=1, # Temperature (use 1 for good performance)
54
+ top_p=0.95,
55
+ )
56
+
57
+ verify_text = lambda txt : '\n'.join([textwrap.fill(txt, width=90) for txt in txt.split('\n')])
58
+ with torch.no_grad():
59
+ output = pipe_line('CONVERSATION: USER: code a program for me to check internet connection in python ? ')
60
+ print(verify_text(output[0]['generated_text']))
61
+
62
+ ```
63
+
64
+ ### Result
65
+
66
+ ```python
67
+ import socket
68
+ import time
69
+
70
+ def check_internet_connection():
71
+ try:
72
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
73
+ s.connect(("www.google.com", 80))
74
+ print("Internet connection is active.")
75
+ except:
76
+ print("Internet connection is not active.")
77
+
78
+ if __name__ == "__main__":
79
+
80
+ check_internet_connection()
81
+ ```
82
+
83
+
84
  # Using Model in OST
85
 
86