Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
model_name = "TheBloke/MelloGPT-AWQ"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
model_name,
|
10 |
+
trust_remote_code=True,
|
11 |
+
torch_dtype=torch.float16,
|
12 |
+
device_map="auto"
|
13 |
+
)
|
14 |
+
|
15 |
+
def chat(input_text):
|
16 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
|
17 |
+
output = model.generate(**inputs, max_new_tokens=150)
|
18 |
+
reply = tokenizer.decode(output[0], skip_special_tokens=True)
|
19 |
+
return reply
|
20 |
+
|
21 |
+
gr.Interface(fn=chat, inputs="text", outputs="text").launch()
|
22 |
+
|