Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,17 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
model_id = "Datangtang/lora_lab2_model_1B"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cpu")
|
| 9 |
+
|
| 10 |
+
def chat_fn(message):
|
| 11 |
+
inputs = tokenizer(message, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(**inputs, max_new_tokens=150)
|
| 13 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
|
| 15 |
+
demo = gr.Interface(fn=chat_fn, inputs="text", outputs="text", title="My Finetuned LLM Chat")
|
| 16 |
|
|
|
|
| 17 |
demo.launch()
|