dylanmeca commited on
Commit
fa8be0b
Β·
1 Parent(s): a0755a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
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
- return answer
 
17
 
18
  # User input
19
- chatbot = gr.Interface(
20
- fn=answer_chatgpt,
21
- inputs=["text", "text"],
22
- outputs="text",
23
- title="πŸ€– ChatGPT-Python 🐍",
24
- description="ChatGPT-Python is a software that allows you to talk to GPT-3 with a web interface using the openai api"
25
- )
26
- chatbot.launch()
 
 
 
 
 
 
 
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)