hectorjelly commited on
Commit
4628266
1 Parent(s): 91b6eab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -20,11 +20,15 @@ def setup_openai(api_key):
20
  openai.api_key = api_key
21
  return "API Key Set Successfully!"
22
 
23
- def ask_joe(api_key, text, btn_clear):
24
- # If button clicked, clear the conversation
25
- if btn_clear:
26
- conversation_history.clear()
27
 
 
 
 
 
 
 
28
  # set up the api_key
29
  setup_openai(api_key)
30
 
@@ -58,15 +62,17 @@ def ask_joe(api_key, text, btn_clear):
58
 
59
  return model_message
60
 
61
-
 
 
62
  iface = gr.Interface(
63
  fn=ask_joe,
64
  inputs=[
65
  gr.inputs.Textbox(label="OpenAI API Key"),
66
  gr.inputs.Textbox(label="Enter your question here. More detail = Better results"),
67
- gr.inputs.Button(label="Clear Conversation") # Button to clear the conversation
68
  ],
69
- outputs=gr.outputs.Textbox(label="Joe's Response"),
70
  )
71
 
72
  iface.launch()
 
20
  openai.api_key = api_key
21
  return "API Key Set Successfully!"
22
 
23
+ def on_button_click(btn):
24
+ return "You pressed the button!"
 
 
25
 
26
+ def ask_joe(api_key, text, btn_press):
27
+ global conversation_history
28
+
29
+ if btn_press:
30
+ return on_button_click(btn_press)
31
+
32
  # set up the api_key
33
  setup_openai(api_key)
34
 
 
62
 
63
  return model_message
64
 
65
+ button = gr.Button("Press Me")
66
+ button.click(on_button_click, outputs="text")
67
+
68
  iface = gr.Interface(
69
  fn=ask_joe,
70
  inputs=[
71
  gr.inputs.Textbox(label="OpenAI API Key"),
72
  gr.inputs.Textbox(label="Enter your question here. More detail = Better results"),
73
+ button
74
  ],
75
+ outputs=gr.outputs.Textbox(label="Joe's Response")
76
  )
77
 
78
  iface.launch()