Nimra064 commited on
Commit
18f0ff7
·
1 Parent(s): f138405

Chatgpt_box

Browse files
Files changed (1) hide show
  1. Chatbox.py +27 -0
Chatbox.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+
5
+ openai.api_key="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"
6
+
7
+ message=[{ "role" : "system" , "content" : "You are a helpful and kind AI Assistant." }]
8
+
9
+ def user_input(input):
10
+ if input:
11
+ input_message={"role" : "user" , "content" : input}
12
+ message.append(input_message)
13
+ chat = openai.ChatCompletion.create( model = 'gpt-3.5-turbo' , messages=message)
14
+ reply=chat.choices[0].message.content
15
+ output_message={"role" : "assistant" , "content" : reply}
16
+ message.append(output_message)
17
+
18
+ return reply
19
+
20
+ input=gr.inputs.Textbox(lines=7 , label='Chat with AI')
21
+ output=gr.outputs.Textbox(label='replay')
22
+
23
+ interface=gr.Interface(fn=user_input, inputs=input, outputs=output, title="AI Chatbot",
24
+ description="Ask anything you want",
25
+ theme="compact").launch(share=True)
26
+
27
+ interface.launch()