File size: 911 Bytes
f190541
4ff7534
 
f190541
 
 
 
 
 
 
 
 
 
4ff7534
 
 
 
 
df87737
 
 
 
4ff7534
e2ed400
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
import gradio as gr
 
# Tải mô hình và tokenizer
tokenizer = AutoTokenizer.from_pretrained("antphb/DS-Chatbox-gpt2-vietnamese-V3")
model = AutoModelForCausalLM.from_pretrained("antphb/DS-Chatbox-gpt2-vietnamese-V3")

# Tạo pipeline cho text-generation
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

# Định nghĩa hàm trả lời câu hỏi
def chat(input_text):
    response = pipe(input_text, max_length=150, num_return_sequences=1)
    return response[0]['generated_text']

iface = gr.Interface(fn=chat, 
                     inputs="text", 
                     outputs="text", 
                     title="Chat với GPT tiếng Việt", 
                     description="Nhập câu hỏi hoặc yêu cầu của bạn và mô hình sẽ trả lời",
                     live=True)


iface.launch()