Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import datetime
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
from tools.final_answer import FinalAnswerTool
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
# Tool to create a personalized greeting repeated a specific number of times.
|
| 9 |
@tool
|
|
@@ -42,8 +43,11 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 42 |
with open("prompts.yaml", 'r') as stream:
|
| 43 |
prompt_templates = yaml.safe_load(stream)
|
| 44 |
|
| 45 |
-
# ----- Initialize agent
|
| 46 |
def initialize_agent(api_key: str):
|
|
|
|
|
|
|
|
|
|
| 47 |
model = OpenAIServerModel(
|
| 48 |
max_tokens=2096,
|
| 49 |
temperature=0.5,
|
|
@@ -65,39 +69,8 @@ def initialize_agent(api_key: str):
|
|
| 65 |
)
|
| 66 |
return agent
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
def set_api_key(api_key: str):
|
| 73 |
-
global AGENT
|
| 74 |
-
AGENT = initialize_agent(api_key)
|
| 75 |
-
return "Agent initialized! You can now enter your queries below."
|
| 76 |
-
|
| 77 |
-
def ask_agent(user_query: str):
|
| 78 |
-
global AGENT
|
| 79 |
-
if AGENT is None:
|
| 80 |
-
return "Please enter your OpenAI API key first."
|
| 81 |
-
response = AGENT.run(user_query)
|
| 82 |
-
return response
|
| 83 |
-
|
| 84 |
-
# ----- Gradio interface -----
|
| 85 |
-
with gr.Blocks() as demo:
|
| 86 |
-
gr.Markdown("## Enter your OpenAI API key and start querying the agent")
|
| 87 |
-
|
| 88 |
-
with gr.Row():
|
| 89 |
-
api_key_input = gr.Textbox(label="OpenAI API Key", placeholder="sk-...", type="password")
|
| 90 |
-
api_key_button = gr.Button("Initialize Agent")
|
| 91 |
-
|
| 92 |
-
init_output = gr.Textbox(label="Status", interactive=False)
|
| 93 |
-
|
| 94 |
-
with gr.Row():
|
| 95 |
-
user_query_input = gr.Textbox(label="Enter your query here", placeholder="Ask something...")
|
| 96 |
-
submit_query_button = gr.Button("Submit Query")
|
| 97 |
-
|
| 98 |
-
query_output = gr.Textbox(label="Agent Response", interactive=False)
|
| 99 |
-
|
| 100 |
-
api_key_button.click(set_api_key, inputs=api_key_input, outputs=init_output)
|
| 101 |
-
submit_query_button.click(ask_agent, inputs=user_query_input, outputs=query_output)
|
| 102 |
|
| 103 |
-
demo.launch()
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
from tools.final_answer import FinalAnswerTool
|
| 6 |
+
|
| 7 |
+
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
# Tool to create a personalized greeting repeated a specific number of times.
|
| 10 |
@tool
|
|
|
|
| 43 |
with open("prompts.yaml", 'r') as stream:
|
| 44 |
prompt_templates = yaml.safe_load(stream)
|
| 45 |
|
| 46 |
+
# ----- Initialize agent function -----
|
| 47 |
def initialize_agent(api_key: str):
|
| 48 |
+
"""
|
| 49 |
+
Initialize the CodeAgent with the user-provided OpenAI API key.
|
| 50 |
+
"""
|
| 51 |
model = OpenAIServerModel(
|
| 52 |
max_tokens=2096,
|
| 53 |
temperature=0.5,
|
|
|
|
| 69 |
)
|
| 70 |
return agent
|
| 71 |
|
| 72 |
+
# Launch Gradio interface with API key input
|
| 73 |
+
def run_agent_with_api_key(api_key: str):
|
| 74 |
+
agent = initialize_agent(api_key)
|
| 75 |
+
GradioUI(agent).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
|
|