Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,32 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
# चैट हिस्ट्री को सिर्फ प्रश्न-उत्तर के फॉर्मेट में रखें
|
10 |
-
formatted_history = "\n".join([f"User: {q}\nAI: {a}" for q, a in chat_history])
|
11 |
-
prompt = f"{formatted_history}\nUser: {question}\nAI:"
|
12 |
-
|
13 |
-
# AI से जवाब लें
|
14 |
-
response = model(prompt)
|
15 |
-
ai_answer = response.generated_responses[-1]
|
16 |
-
|
17 |
-
# चैट हिस्ट्री को अपडेट करें
|
18 |
-
chat_history.append((question, ai_answer))
|
19 |
return "", chat_history
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
gr.Markdown("# 🎓 छात्रों के लिए प्रश्न-उत्तर AI")
|
28 |
-
gr.Markdown("यहां अपना प्रश्न लिखें और AI आपको उत्तर देगा!")
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
clear = gr.Button("साफ़ करें")
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
|
|
1 |
+
import gradio as gr
|
|
|
2 |
|
3 |
+
# यहाँ आप अपने AI मॉडल या API को कॉल करें
|
4 |
+
def respond_to_message(message, chat_history):
|
5 |
+
# सरल उदाहरण: यूजर मैसेज को एआई की तरह जवाब देता है
|
6 |
+
bot_message = f"AI: आपने पूछा: {message}"
|
7 |
+
chat_history.append((message, bot_message))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
return "", chat_history
|
9 |
|
10 |
+
with gr.Blocks() as demo:
|
11 |
+
chatbot = gr.Chatbot(label="AI चैट बोर्ड")
|
12 |
+
msg = gr.Textbox(label="आपका मैसेज")
|
13 |
+
clear = gr.ClearButton([msg, chatbot])
|
14 |
+
|
15 |
+
msg.submit(respond_to_message, [msg, chatbot], [msg, chatbot])
|
16 |
|
17 |
+
demo.launch()
|
18 |
+
import openai
|
|
|
|
|
19 |
|
20 |
+
# OpenAI के लिए (उदाहरण)
|
21 |
+
openai.api_key = "YOUR_API_KEY"
|
|
|
22 |
|
23 |
+
def respond_to_message(message, chat_history):
|
24 |
+
response = openai.ChatCompletion.create(
|
25 |
+
model="gpt-3.5-turbo",
|
26 |
+
messages=[{"role": "user", "content": message}]
|
27 |
+
)
|
28 |
+
bot_message = response.choices[0].message['content']
|
29 |
+
chat_history.append((message, bot_message))
|
30 |
+
return "", chat_history
|
31 |
|
32 |
+
|