Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,57 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return "", chat_history
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import time
|
| 4 |
|
| 5 |
+
# मॉडल लोड करें (ChatGPT जैसा अनुभव के लिए आप facebook/blenderbot-400M-distill, gpt2, या google/gemma-2b-it भी ले सकते हैं)
|
| 6 |
+
model_name = "facebook/blenderbot-400M-distill"
|
| 7 |
+
chatbot = pipeline("conversational", model=model_name)
|
| 8 |
|
| 9 |
+
# सिस्टम मैसेज/वेलकम मैसेज
|
| 10 |
+
SYSTEM_PROMPT = """आप एक मददगार, विनम्र और ज्ञानवर्धक AI सहायक हैं।
|
| 11 |
+
आप छात्रों के सवालों का जवाब देते हैं और उनकी मदद करते हैं।"""
|
| 12 |
+
|
| 13 |
+
# कस्टम थीम और लेआउट
|
| 14 |
+
theme = gr.themes.Soft(
|
| 15 |
+
primary_hue="teal",
|
| 16 |
+
secondary_hue="teal",
|
| 17 |
+
neutral_hue="slate",
|
| 18 |
+
font=["Roboto", "ui-sans-serif", "sans-serif"],
|
| 19 |
+
font_mono=["Roboto Mono", "ui-monospace", "monospace"]
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# चैट फंक्शन
|
| 23 |
+
def chat_with_ai(message, chat_history):
|
| 24 |
+
# सिस्टम प्रॉम्प्ट को चैट हिस्ट्री में जोड़ें (यदि पहली बार चैट कर रहे हैं)
|
| 25 |
+
if not chat_history:
|
| 26 |
+
chat_history.append((None, "नमस्ते! मैं आपकी कैसे मदद कर सकता हूँ?"))
|
| 27 |
+
|
| 28 |
+
# AI को मैसेज भेजें
|
| 29 |
+
conversation = chatbot(message)
|
| 30 |
+
ai_response = conversation.generated_responses[-1]
|
| 31 |
+
|
| 32 |
+
# चैट हिस्ट्री अपडेट करें
|
| 33 |
+
chat_history.append((message, ai_response))
|
| 34 |
return "", chat_history
|
| 35 |
|
| 36 |
+
# साफ़ करने का फंक्शन
|
| 37 |
+
def clear_chat():
|
| 38 |
+
return [], []
|
| 39 |
+
|
| 40 |
+
# एडवांस्ड UI बनाएं
|
| 41 |
+
with gr.Blocks(theme=theme, title="AI चैटबोर्ड | छात्र सहायक") as demo:
|
| 42 |
+
gr.Markdown("# 🚀 AI चैटबोर्ड – छात्रों के लिए सहायक")
|
| 43 |
+
gr.Markdown("यहां आप अपने सवाल पूछ सकते हैं और AI आपको जवाब देगा!")
|
| 44 |
+
|
| 45 |
+
chatbot = gr.Chatbot(label="चैट", height=500)
|
| 46 |
+
msg = gr.Textbox(label="आपका सवाल", placeholder="यहां लिखें...")
|
| 47 |
+
clear = gr.Button("साफ़ करें", variant="secondary")
|
| 48 |
+
|
| 49 |
+
msg.submit(chat_with_ai, [msg, chatbot], [msg, chatbot])
|
| 50 |
+
clear.click(clear_chat, None, chatbot)
|
| 51 |
+
|
| 52 |
+
# फुटर/क्रेडिट
|
| 53 |
+
gr.Markdown("---")
|
| 54 |
+
gr.Markdown("**बनाया गया: Gradio + Hugging Face + Transformers**")
|
| 55 |
+
|
| 56 |
+
demo.launch(share=False)
|
| 57 |
|
|
|