Bagda commited on
Commit
3b5b74a
·
verified ·
1 Parent(s): 263e873

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -1,4 +1,28 @@
 
 
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
 
4
  from datasets import load_dataset
 
1
+ import gradio as gr
2
+ import openai
3
 
4
+ # OpenAI API Key (यहाँ अपनी API Key डालें)
5
+ openai.api_key = "YOUR_API_KEY"
6
+
7
+ # Backend Function: यूजर का मैसेज लेकर OpenAI से रिस्पॉन्स लाता है
8
+ def respond_to_message(message, chat_history):
9
+ response = openai.ChatCompletion.create(
10
+ model="gpt-3.5-turbo",
11
+ messages=[{"role": "user", "content": message}]
12
+ )
13
+ bot_message = response.choices[0].message['content']
14
+ chat_history.append((message, bot_message))
15
+ return "", chat_history
16
+
17
+ # Frontend: Gradio UI
18
+ with gr.Blocks() as demo:
19
+ chatbot = gr.Chatbot(label="AI चैट बोर्ड")
20
+ msg = gr.Textbox(label="आपका मैसेज")
21
+ clear = gr.ClearButton([msg, chatbot])
22
+
23
+ msg.submit(respond_to_message, [msg, chatbot], [msg, chatbot])
24
+
25
+ demo.launch()
26
 
27
 
28
  from datasets import load_dataset