File size: 2,768 Bytes
8118795
cbc7e45
b848ccf
8118795
b848ccf
 
 
f7d38d2
b848ccf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbc7e45
8118795
b848ccf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8118795
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
from transformers import pipeline
import time

# मॉडल लोड करें (ChatGPT जैसा अनुभव के लिए आप facebook/blenderbot-400M-distill, gpt2, या google/gemma-2b-it भी ले सकते हैं)
model_name = "facebook/blenderbot-400M-distill"
chatbot = pipeline("conversational", model=model_name)

# सिस्टम मैसेज/वेलकम मैसेज
SYSTEM_PROMPT = """आप एक मददगार, विनम्र और ज्ञानवर्धक AI सहायक हैं। 
आप छात्रों के सवालों का जवाब देते हैं और उनकी मदद करते हैं।"""

# कस्टम थीम और लेआउट
theme = gr.themes.Soft(
    primary_hue="teal",
    secondary_hue="teal",
    neutral_hue="slate",
    font=["Roboto", "ui-sans-serif", "sans-serif"],
    font_mono=["Roboto Mono", "ui-monospace", "monospace"]
)

# चैट फंक्शन
def chat_with_ai(message, chat_history):
    # सिस्टम प्रॉम्प्ट को चैट हिस्ट्री में जोड़ें (यदि पहली बार चैट कर रहे हैं)
    if not chat_history:
        chat_history.append((None, "नमस्ते! मैं आपकी कैसे मदद कर सकता हूँ?"))
    
    # AI को मैसेज भेजें
    conversation = chatbot(message)
    ai_response = conversation.generated_responses[-1]
    
    # चैट हिस्ट्री अपडेट करें
    chat_history.append((message, ai_response))
    return "", chat_history

# साफ़ करने का फंक्शन
def clear_chat():
    return [], []

# एडवांस्ड UI बनाएं
with gr.Blocks(theme=theme, title="AI चैटबोर्ड | छात्र सहायक") as demo:
    gr.Markdown("# 🚀 AI चैटबोर्ड – छात्रों के लिए सहायक")
    gr.Markdown("यहां आप अपने सवाल पूछ सकते हैं और AI आपको जवाब देगा!")
    
    chatbot = gr.Chatbot(label="चैट", height=500)
    msg = gr.Textbox(label="आपका सवाल", placeholder="यहां लिखें...")
    clear = gr.Button("साफ़ करें", variant="secondary")
    
    msg.submit(chat_with_ai, [msg, chatbot], [msg, chatbot])
    clear.click(clear_chat, None, chatbot)
    
    # फुटर/क्रेडिट
    gr.Markdown("---")
    gr.Markdown("**बनाया गया: Gradio + Hugging Face + Transformers**")

demo.launch(share=False)