|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
model = pipeline("conversational", model="facebook/blenderbot-400M-distill") |
|
|
|
|
|
|
|
|
def qna_ai(question, chat_history): |
|
|
|
|
|
formatted_history = "\n".join([f"User: {q}\nAI: {a}" for q, a in chat_history]) |
|
|
prompt = f"{formatted_history}\nUser: {question}\nAI:" |
|
|
|
|
|
|
|
|
response = model(prompt) |
|
|
ai_answer = response.generated_responses[-1] |
|
|
|
|
|
|
|
|
chat_history.append((question, ai_answer)) |
|
|
return "", chat_history |
|
|
|
|
|
|
|
|
def clear_chat(): |
|
|
return [], [] |
|
|
|
|
|
|
|
|
with gr.Blocks(title="छात्र सहायक AI", theme=gr.themes.Soft()) as demo: |
|
|
gr.Markdown("# 🎓 छात्रों के लिए प्रश्न-उत्तर AI") |
|
|
gr.Markdown("यहां अपना प्रश्न लिखें और AI आपको उत्तर देगा!") |
|
|
|
|
|
chatbot = gr.Chatbot(label="चैट", height=400) |
|
|
msg = gr.Textbox(label="प्रश्न", placeholder="यहां लिखें...") |
|
|
clear = gr.Button("साफ़ करें") |
|
|
|
|
|
msg.submit(qna_ai, [msg, chatbot], [msg, chatbot]) |
|
|
clear.click(clear_chat, None, chatbot) |
|
|
|
|
|
demo.launch() |
|
|
|