File size: 856 Bytes
f655cc3
034ec07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr
from transformers import pipeline

# Thay mô hình nếu bạn biết rõ hơn mô hình cũ
reply_pipeline = pipeline("text-generation", model="microsoft/DialoGPT-medium")

def reply_comment(comment):
    prompt = f"Trả lời một cách thân thiện, tự nhiên, có thể hài hước:\nBình luận: {comment}\nTrả lời:"
    response = reply_pipeline(prompt, max_length=100, do_sample=True)
    return response[0]['generated_text'].replace(prompt, "").strip()

gr.Interface(
    fn=reply_comment,
    inputs=gr.Textbox(label="Nhập bình luận cần trả lời", placeholder="Ví dụ: Sản phẩm này có tốt không vậy?"),
    outputs=gr.Textbox(label="Phản hồi AI"),
    title="Comment Reply AI 🐠",
    description="Nhập một bình luận, AI sẽ đề xuất câu trả lời phù hợp"
).launch()