Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
"""Basic Agent Evaluation Runner - Cleaned Version"""
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
import requests
|
@@ -10,9 +9,8 @@ from tools import build_graph
|
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
class BasicAgent:
|
13 |
-
"""A langgraph agent using CSV-based vector store."""
|
14 |
|
15 |
-
def __init__(self, csv_file_path: str = "
|
16 |
print("BasicAgent initialized.")
|
17 |
self.graph = build_graph(provider="groq", csv_file_path=csv_file_path)
|
18 |
|
@@ -40,7 +38,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
40 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
41 |
and displays the results.
|
42 |
"""
|
43 |
-
# Check authentication
|
44 |
if not profile:
|
45 |
print("User not logged in.")
|
46 |
return "Please Login to Hugging Face with the button.", None
|
@@ -48,16 +45,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
48 |
username = f"{profile.username}"
|
49 |
print(f"User logged in: {username}")
|
50 |
|
51 |
-
# Determine space info
|
52 |
space_id = os.getenv("SPACE_ID")
|
53 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else "Local Development"
|
54 |
|
55 |
-
# API URLs
|
56 |
api_url = DEFAULT_API_URL
|
57 |
questions_url = f"{api_url}/questions"
|
58 |
submit_url = f"{api_url}/submit"
|
59 |
|
60 |
-
# Initialize Agent
|
61 |
try:
|
62 |
agent = BasicAgent() # Make sure your CSV file is named "embeddings.csv" or update the path
|
63 |
except Exception as e:
|
@@ -79,7 +73,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
79 |
print(f"Error fetching questions: {e}")
|
80 |
return f"Error fetching questions: {e}", None
|
81 |
|
82 |
-
# Run Agent on Questions
|
83 |
results_log = []
|
84 |
answers_payload = []
|
85 |
print(f"Running agent on {len(questions_data)} questions...")
|
@@ -113,7 +106,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
113 |
if not answers_payload:
|
114 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
115 |
|
116 |
-
# Submit Results
|
117 |
submission_data = {
|
118 |
"username": username.strip(),
|
119 |
"agent_code": agent_code,
|
@@ -144,7 +136,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
144 |
results_df = pd.DataFrame(results_log)
|
145 |
return status_message, results_df
|
146 |
|
147 |
-
# Gradio Interface
|
148 |
with gr.Blocks() as demo:
|
149 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
150 |
gr.Markdown("""
|
@@ -170,7 +161,6 @@ with gr.Blocks() as demo:
|
|
170 |
if __name__ == "__main__":
|
171 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
172 |
|
173 |
-
# Environment info
|
174 |
space_host = os.getenv("SPACE_HOST")
|
175 |
space_id = os.getenv("SPACE_ID")
|
176 |
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
|
|
9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
10 |
|
11 |
class BasicAgent:
|
|
|
12 |
|
13 |
+
def __init__(self, csv_file_path: str = "embedding_database.csv"):
|
14 |
print("BasicAgent initialized.")
|
15 |
self.graph = build_graph(provider="groq", csv_file_path=csv_file_path)
|
16 |
|
|
|
38 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
39 |
and displays the results.
|
40 |
"""
|
|
|
41 |
if not profile:
|
42 |
print("User not logged in.")
|
43 |
return "Please Login to Hugging Face with the button.", None
|
|
|
45 |
username = f"{profile.username}"
|
46 |
print(f"User logged in: {username}")
|
47 |
|
|
|
48 |
space_id = os.getenv("SPACE_ID")
|
49 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else "Local Development"
|
50 |
|
|
|
51 |
api_url = DEFAULT_API_URL
|
52 |
questions_url = f"{api_url}/questions"
|
53 |
submit_url = f"{api_url}/submit"
|
54 |
|
|
|
55 |
try:
|
56 |
agent = BasicAgent() # Make sure your CSV file is named "embeddings.csv" or update the path
|
57 |
except Exception as e:
|
|
|
73 |
print(f"Error fetching questions: {e}")
|
74 |
return f"Error fetching questions: {e}", None
|
75 |
|
|
|
76 |
results_log = []
|
77 |
answers_payload = []
|
78 |
print(f"Running agent on {len(questions_data)} questions...")
|
|
|
106 |
if not answers_payload:
|
107 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
108 |
|
|
|
109 |
submission_data = {
|
110 |
"username": username.strip(),
|
111 |
"agent_code": agent_code,
|
|
|
136 |
results_df = pd.DataFrame(results_log)
|
137 |
return status_message, results_df
|
138 |
|
|
|
139 |
with gr.Blocks() as demo:
|
140 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
141 |
gr.Markdown("""
|
|
|
161 |
if __name__ == "__main__":
|
162 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
163 |
|
|
|
164 |
space_host = os.getenv("SPACE_HOST")
|
165 |
space_id = os.getenv("SPACE_ID")
|
166 |
|