File size: 1,872 Bytes
8118795
cbc7e45
8118795
56726b2
 
f7d38d2
56726b2
 
 
 
 
b848ccf
56726b2
 
 
b848ccf
56726b2
 
cbc7e45
8118795
56726b2
b848ccf
 
 
56726b2
 
 
 
b848ccf
56726b2
 
 
 
 
 
8118795
56726b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
from transformers import pipeline

# Hugging Face का कोई भी चैट मॉडल लोड करें (यहाँ facebook/blenderbot-400M-distill उदाहरण है)
model = pipeline("conversational", model="facebook/blenderbot-400M-distill")

# यह फंक्शन AI को प्रश्न भेजता है और उत्तर लेता है
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:"
    
    # AI से जवाब लें
    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()