Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,
|
| 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
|
| 85 |
-
def
|
| 86 |
"""
|
| 87 |
-
|
| 88 |
|
| 89 |
Args:
|
| 90 |
-
api_key (str):
|
|
|
|
| 91 |
|
| 92 |
Returns:
|
| 93 |
-
|
| 94 |
"""
|
| 95 |
agent = initialize_agent(api_key)
|
| 96 |
-
return
|
| 97 |
|
| 98 |
-
# Gradio
|
| 99 |
iface = gr.Interface(
|
| 100 |
-
fn=
|
| 101 |
-
inputs=
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
title="Custom SmolAgent App",
|
| 104 |
-
description="Enter your OpenAI API key to
|
| 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()
|