Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,20 @@
|
|
1 |
-
from
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
model = Llama(model_path=MODEL_PATH)
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
return response['choices'][0]['text']
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
#
|
|
|
17 |
interface.launch()
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Sử dụng tên mô hình từ Hugging Face
|
5 |
+
MODEL_NAME = "vilm/vinallama-2.7b-chat-GGUF"
|
|
|
6 |
|
7 |
+
# Tải mô hình và tokenizer
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
|
|
|
10 |
|
11 |
+
# Hàm chatbot
|
12 |
+
def chatbot(input_text):
|
13 |
+
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
|
14 |
+
outputs = model.generate(inputs["input_ids"], max_length=200, do_sample=True, temperature=0.7)
|
15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return response
|
17 |
|
18 |
+
# Giao diện Gradio
|
19 |
+
interface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Vinamallama Chatbot")
|
20 |
interface.launch()
|