Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,10 @@ import openai
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
# Getting responses using the OpenAI API
|
| 5 |
-
def answer_chatgpt(api_key, message):
|
|
|
|
|
|
|
|
|
|
| 6 |
# OPENAI API KEY
|
| 7 |
openai.api_key = api_key
|
| 8 |
prompt = (f"You are GPT-3, you are in a web interface and reply to my following message: {message}")
|
|
@@ -13,14 +16,21 @@ def answer_chatgpt(api_key, message):
|
|
| 13 |
)
|
| 14 |
# Displaying the answer on the screen
|
| 15 |
answer = response["choices"][0]["text"]
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
# User input
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
)
|
| 26 |
-
chatbot.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
# Getting responses using the OpenAI API
|
| 5 |
+
def answer_chatgpt(api_key, message, history):
|
| 6 |
+
history = history or []
|
| 7 |
+
lista = list(sum(history, ()))
|
| 8 |
+
lista.append(message)
|
| 9 |
# OPENAI API KEY
|
| 10 |
openai.api_key = api_key
|
| 11 |
prompt = (f"You are GPT-3, you are in a web interface and reply to my following message: {message}")
|
|
|
|
| 16 |
)
|
| 17 |
# Displaying the answer on the screen
|
| 18 |
answer = response["choices"][0]["text"]
|
| 19 |
+
history.append((message, answer))
|
| 20 |
+
return history, history
|
| 21 |
|
| 22 |
# User input
|
| 23 |
+
block = gr.Blocks()
|
| 24 |
+
|
| 25 |
+
with block:
|
| 26 |
+
gr.Markdown("""<h1><center>π€ ChatGPT-Python π</center></h1>
|
| 27 |
+
<p><center>ChatGPT-Python is a software that allows you to talk to GPT-3 with a web interface using the openai api</center></p>
|
| 28 |
+
""")
|
| 29 |
+
api_key = gr.Textbox(placeholder="api_key")
|
| 30 |
+
chatbot = gr.Chatbot()
|
| 31 |
+
message = gr.Textbox(placeholder="message")
|
| 32 |
+
state = gr.State()
|
| 33 |
+
submit = gr.Button("Send")
|
| 34 |
+
submit.click(answer_chatgpt, inputs=[api_key, message, state], outputs=[chatbot, state])
|
| 35 |
+
|
| 36 |
+
block.launch(debug=True)
|