hectorjelly commited on
Commit
716463f
·
1 Parent(s): 878a165

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,9 +1,7 @@
 
1
  import gradio as gr
2
  import openai
3
 
4
- import openai
5
- import gradio as gr
6
-
7
  # Initialize the conversation history
8
  conversation_history = [
9
  {
@@ -19,12 +17,14 @@ conversation_history = [
19
  }
20
  ]
21
 
 
22
  def setup_openai(api_key):
23
  openai.api_key = api_key
24
  return "API Key Set Successfully!"
25
 
 
26
  def ask_joe(api_key, text):
27
- # set up the api_key
28
  setup_openai(api_key)
29
 
30
  # Add the user's message to the conversation history
@@ -50,8 +50,14 @@ def ask_joe(api_key, text):
50
  "content": model_message
51
  })
52
 
 
53
  return model_message
54
 
55
- iface = gr.Interface(fn=ask_joe, inputs=["text", "text"], outputs="text")
 
 
 
 
56
 
 
57
  iface.launch()
 
1
+ # Import necessary libraries
2
  import gradio as gr
3
  import openai
4
 
 
 
 
5
  # Initialize the conversation history
6
  conversation_history = [
7
  {
 
17
  }
18
  ]
19
 
20
+ # Function to setup OpenAI with the provided api_key
21
  def setup_openai(api_key):
22
  openai.api_key = api_key
23
  return "API Key Set Successfully!"
24
 
25
+ # Function to interact with Joe
26
  def ask_joe(api_key, text):
27
+ # Set up the OpenAI API with the provided key
28
  setup_openai(api_key)
29
 
30
  # Add the user's message to the conversation history
 
50
  "content": model_message
51
  })
52
 
53
+ # Return the model's response
54
  return model_message
55
 
56
+ # Create the Gradio Interface with function ask_joe, inputs as 'api_key' and 'text' and output as 'text'
57
+ iface = gr.Interface(fn=ask_joe,
58
+ inputs=[gr.inputs.Textbox(lines=1, label="API Key"), gr.inputs.Textbox(lines=2, label="User Text")],
59
+ outputs=gr.outputs.Textbox(label="Joe's Response")
60
+ )
61
 
62
+ # Launch the Gradio Interface
63
  iface.launch()