Spaces:
Sleeping
Sleeping
Commit
·
b8cd44a
1
Parent(s):
a889263
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
#openai.api_key = os.environ["apikey"]
|
| 5 |
+
|
| 6 |
+
message=[{"role":"system","content":"You are expert in explaining things in brief way"}]
|
| 7 |
+
try:
|
| 8 |
+
openai.api_key="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"
|
| 9 |
+
def ChatReply(Question):
|
| 10 |
+
|
| 11 |
+
message.append({"role":"user","content": Question})
|
| 12 |
+
response = openai.ChatCompletion.create(
|
| 13 |
+
model="gpt-3.5-turbo",
|
| 14 |
+
messages= message)
|
| 15 |
+
|
| 16 |
+
reply= response["choices"][0]["message"]["content"]
|
| 17 |
+
message.append({"role":"assistant","content":reply})
|
| 18 |
+
return reply
|
| 19 |
+
except:
|
| 20 |
+
print("Try Again")
|
| 21 |
+
|
| 22 |
+
reply = gr.Interface(
|
| 23 |
+
fn=ChatReply,
|
| 24 |
+
inputs=gr.Textbox(label="Explainer", placeholder="E.g. Flutter?"),
|
| 25 |
+
outputs=gr.Textbox(label="Get a simple answer in return:"),
|
| 26 |
+
theme="dark",
|
| 27 |
+
title="Explain things in simple way"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
reply.launch(share=True)
|