Spaces:
Runtime error
Runtime error
Add openai bot
Browse files
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
def greet(name):
|
4 |
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
|
4 |
def greet(name):
|
5 |
return "Hello " + name + "!!"
|
6 |
|
7 |
+
openai.api_key = "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"
|
8 |
+
|
9 |
+
def chatbot(input):
|
10 |
+
messages = []
|
11 |
+
if input:
|
12 |
+
context = "Summarise the following input where possible creating a wise acrostic:"
|
13 |
+
messages.append({"role": "user", "content": context + input})
|
14 |
+
chat = openai.ChatCompletion.create(
|
15 |
+
model="gpt-3.5-turbo", messages=messages
|
16 |
+
)
|
17 |
+
reply = chat.choices[0].message.content
|
18 |
+
messages.append({"role": "assistant", "content": reply})
|
19 |
+
return reply
|
20 |
+
|
21 |
+
inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
22 |
+
outputs = gr.outputs.Textbox(label="Reply")
|
23 |
+
|
24 |
+
iface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot", description="Ask anything you want", theme="compact").launch(share=True)
|
25 |
iface.launch()
|