Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,24 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
from memory import update_memory, check_memory
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", trust_remote_code=True)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
if __name__ == "__main__":
|
29 |
-
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
|
|
3 |
|
4 |
+
# β
Model name update karo
|
5 |
+
model_name = "TheBloke/Pygmalion-13B-SuperHOT-8K-GPTQ"
|
6 |
|
7 |
+
# β
Tokenizer Load karo
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
9 |
|
10 |
+
# β
Model Load karo (Automatic Device Selection)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
|
12 |
+
|
13 |
+
def chat(prompt):
|
14 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
15 |
+
output = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.9)
|
16 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
17 |
+
|
18 |
+
# β
Test Chat
|
19 |
+
while True:
|
20 |
+
user_input = input("You: ")
|
21 |
+
if user_input.lower() in ["exit", "quit"]:
|
22 |
+
break
|
23 |
+
response = chat(user_input)
|
24 |
+
print("AI:", response)
|
|
|
|
|
|