phucdt89s's picture
Update app.py
09f84eb verified
raw
history blame contribute delete
799 Bytes
from transformers import AutoModelForCausalLM, AutoTokenizer
import gradio as gr
# Sử dụng tên mô hình từ Hugging Face
MODEL_NAME = "vilm/vinallama-2.7b-chat-GGUF"
# Tải mô hình và tokenizer
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
# Hàm chatbot
def chatbot(input_text):
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(inputs["input_ids"], max_length=200, do_sample=True, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
# Giao diện Gradio
interface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Vinamallama Chatbot")
interface.launch()