Update app.py
#591
by Thanatos39 - opened
app.py
CHANGED
|
@@ -143,7 +143,46 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 143 |
# --- Build Gradio Interface using Blocks ---
|
| 144 |
with gr.Blocks() as demo:
|
| 145 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
| 146 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
"""
|
| 148 |
**Instructions:**
|
| 149 |
|
|
@@ -151,7 +190,6 @@ with gr.Blocks() as demo:
|
|
| 151 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
| 152 |
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
| 153 |
|
| 154 |
-
---
|
| 155 |
**Disclaimers:**
|
| 156 |
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).
|
| 157 |
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.
|
|
|
|
| 143 |
# --- Build Gradio Interface using Blocks ---
|
| 144 |
with gr.Blocks() as demo:
|
| 145 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
| 146 |
+
gr.Markdown(# ==========================================
|
| 147 |
+
# SECTION 1: IMPORTS & TOOL DEFINITIONS
|
| 148 |
+
# ==========================================
|
| 149 |
+
from smolagents import CodeAgent, LiteLLMModel, tool
|
| 150 |
+
import pandas as pd
|
| 151 |
+
import requests
|
| 152 |
+
from bs4 import BeautifulSoup
|
| 153 |
+
|
| 154 |
+
# Paste your custom high-yield tools here
|
| 155 |
+
@tool
|
| 156 |
+
def inspect_dataframe(file_path: str, operation: str, query_code: str = None) -> str:
|
| 157 |
+
# (Your dataframe tool logic here...)
|
| 158 |
+
pass
|
| 159 |
+
|
| 160 |
+
@tool
|
| 161 |
+
def fetch_webpage_content(url: str) -> str:
|
| 162 |
+
# (Your scraper tool logic here...)
|
| 163 |
+
pass
|
| 164 |
+
|
| 165 |
+
# ==========================================
|
| 166 |
+
# SECTION 2: INITIALIZE THE INTENT ENGINE
|
| 167 |
+
# ==========================================
|
| 168 |
+
# Ensure you have set your HF_TOKEN secret in Space Settings!
|
| 169 |
+
model = LiteLLMModel(model_id="huggingface/Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 170 |
+
|
| 171 |
+
# Instantiate your agent with the tools attached
|
| 172 |
+
agent = CodeAgent(
|
| 173 |
+
tools=[inspect_dataframe, fetch_webpage_content],
|
| 174 |
+
model=model,
|
| 175 |
+
additional_authorized_imports=["pandas", "numpy", "json", "datetime", "re", "bs4"]
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
# ==========================================
|
| 179 |
+
# SECTION 3: CONNECT TO THE TEMPLATE RUNNER
|
| 180 |
+
# ==========================================
|
| 181 |
+
# The original template space comes with a Gradio UI block or a loop
|
| 182 |
+
# that cycles through questions. Leave that layout block intact at the bottom.
|
| 183 |
+
# Inside that function block where it evaluates user questions, change it to call your agent:
|
| 184 |
+
# e.g., raw_output = agent.run(evaluation_question)
|
| 185 |
+
|
| 186 |
"""
|
| 187 |
**Instructions:**
|
| 188 |
|
|
|
|
| 190 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
| 191 |
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
| 192 |
|
|
|
|
| 193 |
**Disclaimers:**
|
| 194 |
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).
|
| 195 |
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.
|