hectorjelly commited on
Commit
0711a77
1 Parent(s): 5af4660

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -20,10 +20,19 @@ 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):
 
 
 
 
 
 
 
24
  # set up the api_key
25
  setup_openai(api_key)
26
 
 
 
27
  # Add the user's message to the conversation history
28
  conversation_history.append({
29
  "role": "user",
@@ -52,8 +61,23 @@ def ask_joe(api_key, text):
52
  f.write(f'User: {text}\n')
53
  f.write(f'AI: {model_message}\n')
54
 
55
- return model_message
56
 
57
- iface = gr.Interface(fn=ask_joe, inputs=[gr.inputs.Textbox(label="OpenAI API Key"), gr.inputs.Textbox(label="Enter your poker question here. More detail = Better results")], outputs=gr.outputs.Textbox(label="Joe's Response"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- iface.launch()
 
20
  openai.api_key = api_key
21
  return "API Key Set Successfully!"
22
 
23
+ def ask_joe(api_key, text, clear, history):
24
+ if clear:
25
+ # Reset the conversation history
26
+ history.data = [{
27
+ # The initial conversation prompt...
28
+ }]
29
+
30
+
31
  # set up the api_key
32
  setup_openai(api_key)
33
 
34
+
35
+
36
  # Add the user's message to the conversation history
37
  conversation_history.append({
38
  "role": "user",
 
61
  f.write(f'User: {text}\n')
62
  f.write(f'AI: {model_message}\n')
63
 
64
+ return model_message, False, history
65
 
66
+
67
+ history = gr.State([])
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
+ gr.inputs.Checkbox(label="Clear Conversation")
74
+ ],
75
+ outputs=[
76
+ gr.outputs.Textbox(label="Joe's Response"),
77
+ gr.outputs.Hidden(), # The 'clear' state
78
+ gr.outputs.Hidden() # The 'history' state
79
+ ],
80
+ state=history
81
+ )
82
 
83
+ iface.launch()