Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model_id = "TinyLlama/TinyLlama-1.1B-Chat-v0.3"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
7 |
+
|
8 |
+
pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer, max_new_tokens=200, do_sample=True)
|
9 |
+
|
10 |
+
def chat(user_input):
|
11 |
+
res = pipe(user_input)[0]["generated_text"]
|
12 |
+
return res[len(user_input):] # chỉ trả lời, không lặp lại câu hỏi
|
13 |
+
|
14 |
+
gr.Interface(fn=chat, inputs="text", outputs="text", title="🤖 TinyLlama Chatbot").launch()
|