dlaima commited on
Commit
1e0699c
·
verified ·
1 Parent(s): ee0f911

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, load_tool, tool
2
  import datetime
3
  import pytz
4
  import yaml
@@ -81,27 +81,31 @@ def initialize_agent(api_key: str):
81
 
82
  return agent
83
 
84
- # ----- Gradio Interface -----
85
- def launch_agent(api_key: str):
86
  """
87
- Launches the Gradio interface for the CodeAgent after receiving the API key.
88
 
89
  Args:
90
- api_key (str): User's OpenAI API key.
 
91
 
92
  Returns:
93
- None
94
  """
95
  agent = initialize_agent(api_key)
96
- return GradioUI(agent).launch(share=True)
97
 
98
- # Gradio input for API key
99
  iface = gr.Interface(
100
- fn=launch_agent,
101
- inputs=gr.Textbox(label="Enter your OpenAI API Key", type="password"),
102
- outputs="text",
 
 
 
103
  title="Custom SmolAgent App",
104
- description="Enter your OpenAI API key to use the agent."
105
  )
106
 
107
  iface.launch()
 
1
+ from smolagents import CodeAgent, OpenAIServerModel, load_tool, tool
2
  import datetime
3
  import pytz
4
  import yaml
 
81
 
82
  return agent
83
 
84
+ # ----- Gradio Query Function -----
85
+ def agent_response(api_key: str, user_query: str):
86
  """
87
+ Responds to a user query using the CodeAgent initialized with the API key.
88
 
89
  Args:
90
+ api_key (str): OpenAI API key provided by the user.
91
+ user_query (str): The user's query for the agent.
92
 
93
  Returns:
94
+ str: Agent's response.
95
  """
96
  agent = initialize_agent(api_key)
97
+ return agent.run(user_query) # Run the agent on the user's query
98
 
99
+ # ----- Gradio Interface -----
100
  iface = gr.Interface(
101
+ fn=agent_response,
102
+ inputs=[
103
+ gr.Textbox(label="Enter your OpenAI API Key", type="password"),
104
+ gr.Textbox(label="Your Query", placeholder="Type your question here...")
105
+ ],
106
+ outputs=gr.Textbox(label="Agent Response"),
107
  title="Custom SmolAgent App",
108
+ description="Enter your OpenAI API key and ask a question to the agent."
109
  )
110
 
111
  iface.launch()