Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import pandas as pd
|
|
| 9 |
import requests
|
| 10 |
from langchain_community.document_loaders import UnstructuredExcelLoader
|
| 11 |
|
| 12 |
-
from agents import
|
| 13 |
|
| 14 |
# (Keep Constants as is)
|
| 15 |
# --- Constants ---
|
|
@@ -91,8 +91,8 @@ def filter_supported_content_blocks(messages):
|
|
| 91 |
return filtered
|
| 92 |
|
| 93 |
class Agent:
|
| 94 |
-
def __init__(self):
|
| 95 |
-
self.main_agent =
|
| 96 |
print("Agent initialized.")
|
| 97 |
def __call__(self, question: str, file_name: str = "", task_id: str = "") -> str:
|
| 98 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
@@ -110,7 +110,7 @@ class Agent:
|
|
| 110 |
else:
|
| 111 |
return str(content)
|
| 112 |
|
| 113 |
-
def run_and_submit_all(
|
| 114 |
"""
|
| 115 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 116 |
and displays the results.
|
|
@@ -131,11 +131,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 131 |
|
| 132 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 133 |
try:
|
| 134 |
-
|
|
|
|
| 135 |
except Exception as e:
|
| 136 |
print(f"Error instantiating agent: {e}")
|
| 137 |
return f"Error initializing agent: {e}", None
|
| 138 |
-
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 139 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 140 |
print(agent_code)
|
| 141 |
|
|
@@ -246,8 +246,8 @@ with gr.Blocks() as demo:
|
|
| 246 |
|
| 247 |
---
|
| 248 |
**Disclaimers:**
|
| 249 |
-
Once clicking on the "submit
|
| 250 |
-
This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a
|
| 251 |
"""
|
| 252 |
)
|
| 253 |
|
|
@@ -281,6 +281,7 @@ with gr.Blocks() as demo:
|
|
| 281 |
|
| 282 |
run_button.click(
|
| 283 |
fn=run_and_submit_all,
|
|
|
|
| 284 |
outputs=[status_output, results_table]
|
| 285 |
)
|
| 286 |
|
|
|
|
| 9 |
import requests
|
| 10 |
from langchain_community.document_loaders import UnstructuredExcelLoader
|
| 11 |
|
| 12 |
+
from agents import build_supervisor_agent
|
| 13 |
|
| 14 |
# (Keep Constants as is)
|
| 15 |
# --- Constants ---
|
|
|
|
| 91 |
return filtered
|
| 92 |
|
| 93 |
class Agent:
|
| 94 |
+
def __init__(self, main_agent):
|
| 95 |
+
self.main_agent = main_agent
|
| 96 |
print("Agent initialized.")
|
| 97 |
def __call__(self, question: str, file_name: str = "", task_id: str = "") -> str:
|
| 98 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 110 |
else:
|
| 111 |
return str(content)
|
| 112 |
|
| 113 |
+
def run_and_submit_all(profile: gr.OAuthProfile | None, openai_key: str, google_key: str):
|
| 114 |
"""
|
| 115 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 116 |
and displays the results.
|
|
|
|
| 131 |
|
| 132 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 133 |
try:
|
| 134 |
+
agent_instance = build_supervisor_agent(openai_key, google_key)
|
| 135 |
+
agent = Agent(agent_instance)
|
| 136 |
except Exception as e:
|
| 137 |
print(f"Error instantiating agent: {e}")
|
| 138 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 139 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 140 |
print(agent_code)
|
| 141 |
|
|
|
|
| 246 |
|
| 247 |
---
|
| 248 |
**Disclaimers:**
|
| 249 |
+
Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
|
| 250 |
+
This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
|
| 251 |
"""
|
| 252 |
)
|
| 253 |
|
|
|
|
| 281 |
|
| 282 |
run_button.click(
|
| 283 |
fn=run_and_submit_all,
|
| 284 |
+
inputs=[gr.OAuthProfile(), openai_key_box, google_key_box],
|
| 285 |
outputs=[status_output, results_table]
|
| 286 |
)
|
| 287 |
|