Spaces:
Sleeping
Sleeping
first commit
Browse files- .gitignore +2 -0
- agent.py +11 -0
- app.py +24 -19
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
__pycache__/*
|
agent.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# --- Basic Agent Definition ---
|
2 |
+
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
3 |
+
|
4 |
+
class BasicAgent:
|
5 |
+
def __init__(self):
|
6 |
+
print("BasicAgent initialized.")
|
7 |
+
def __call__(self, question: str) -> str:
|
8 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
9 |
+
fixed_answer = "This is a default answer."
|
10 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
11 |
+
return fixed_answer
|
app.py
CHANGED
@@ -4,21 +4,12 @@ import requests
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
|
|
|
|
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
10 |
|
11 |
-
# --- Basic Agent Definition ---
|
12 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
-
class BasicAgent:
|
14 |
-
def __init__(self):
|
15 |
-
print("BasicAgent initialized.")
|
16 |
-
def __call__(self, question: str) -> str:
|
17 |
-
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
18 |
-
fixed_answer = "This is a default answer."
|
19 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
20 |
-
return fixed_answer
|
21 |
-
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
24 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
@@ -139,6 +130,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
139 |
results_df = pd.DataFrame(results_log)
|
140 |
return status_message, results_df
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
# --- Build Gradio Interface using Blocks ---
|
144 |
with gr.Blocks() as demo:
|
@@ -160,16 +162,19 @@ with gr.Blocks() as demo:
|
|
160 |
|
161 |
gr.LoginButton()
|
162 |
|
163 |
-
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
164 |
|
165 |
-
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
166 |
-
# Removed max_rows=10 from DataFrame constructor
|
167 |
-
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
-
run_button.click(
|
170 |
-
fn=run_and_submit_all,
|
171 |
-
outputs=[status_output, results_table]
|
172 |
-
)
|
173 |
|
174 |
if __name__ == "__main__":
|
175 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
|
7 |
+
import agent
|
8 |
+
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
14 |
"""
|
15 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
130 |
results_df = pd.DataFrame(results_log)
|
131 |
return status_message, results_df
|
132 |
|
133 |
+
def test_init_agent_for_chat(text_input, history):
|
134 |
+
# 1. Instantiate Agent ( modify this part to create your agent)
|
135 |
+
try:
|
136 |
+
basicAgent = agent.BasicAgent()
|
137 |
+
except Exception as e:
|
138 |
+
print(f"Error instantiating agent: {e}")
|
139 |
+
return f"Error initializing agent: {e}", None
|
140 |
+
|
141 |
+
submitted_answer = basicAgent(text_input)
|
142 |
+
|
143 |
+
return submitted_answer
|
144 |
|
145 |
# --- Build Gradio Interface using Blocks ---
|
146 |
with gr.Blocks() as demo:
|
|
|
162 |
|
163 |
gr.LoginButton()
|
164 |
|
165 |
+
# run_button = gr.Button("Run Evaluation & Submit All Answers")
|
166 |
|
167 |
+
# status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
168 |
+
# # Removed max_rows=10 from DataFrame constructor
|
169 |
+
# results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
170 |
+
|
171 |
+
# run_button.click(
|
172 |
+
# fn=run_and_submit_all,
|
173 |
+
# outputs=[status_output, results_table]
|
174 |
+
# )
|
175 |
+
|
176 |
+
gr.ChatInterface(test_init_agent_for_chat, type="messages")
|
177 |
|
|
|
|
|
|
|
|
|
178 |
|
179 |
if __name__ == "__main__":
|
180 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|