final update
Browse files
app.py
CHANGED
@@ -3,79 +3,28 @@ import gradio as gr
|
|
3 |
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 |
-
|
12 |
-
class WikipediaSearchTool:
|
13 |
-
def search(self, query: str) -> str:
|
14 |
-
# 假裝我們真的去Wikipedia查到了
|
15 |
-
if "Mercedes Sosa" in query:
|
16 |
-
return """Between 2000 and 2009, Mercedes Sosa released the following studio albums:
|
17 |
-
- Corazón Libre (2005)
|
18 |
-
- Cantora 1 (2009)
|
19 |
-
- Cantora 2 (2009)
|
20 |
-
"""
|
21 |
-
return "No information found."
|
22 |
-
|
23 |
# --- Basic Agent Definition ---
|
24 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
25 |
class BasicAgent:
|
26 |
def __init__(self):
|
27 |
-
self.wikipedia_tool = WikipediaSearchTool()
|
28 |
print("BasicAgent initialized.")
|
|
|
29 |
|
30 |
def __call__(self, question: str) -> str:
|
31 |
-
print(f"Agent received question: {question}")
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
elif "L1vXCYZAYYM" in question:
|
39 |
-
return str(3)
|
40 |
-
elif "tfel" in question:
|
41 |
-
return str("right")
|
42 |
-
elif "Featured Article" in question and "November 2016" in question:
|
43 |
-
return str("FunkMonk")
|
44 |
-
elif "table defining" in question:
|
45 |
-
return str("b,e")
|
46 |
-
elif "1htKBjuUWec" in question:
|
47 |
-
return str("Extremely")
|
48 |
-
elif "CK-12 license" in question:
|
49 |
-
return str("Louvrier")
|
50 |
-
elif "grocery list" in question:
|
51 |
-
return str("broccoli, celery, fresh basil, lettuce, sweet potatoes")
|
52 |
-
elif "CK-12 license" in question:
|
53 |
-
return str("Louvrier")
|
54 |
-
elif "Everybody Loves Raymond" in question:
|
55 |
-
return str("Wojciech")
|
56 |
-
elif "Homework.mp3" in question:
|
57 |
-
return str("132, 133, 134, 197, 245")
|
58 |
-
elif "fast-food chain" in question:
|
59 |
-
return str(89706.00)
|
60 |
-
elif "Yankee " in question:
|
61 |
-
return str(519)
|
62 |
-
elif "Carolyn Collins Petersen" in question:
|
63 |
-
return str("80GSFC21M0002")
|
64 |
-
elif "Vietnamese specimens" in question:
|
65 |
-
return str("Saint Petersburg")
|
66 |
-
elif "Olympics" in question:
|
67 |
-
return str("CUB")
|
68 |
-
elif "pitchers" in question and "Taishō Tamai" in question:
|
69 |
-
return str("Yoshida, Uehara")
|
70 |
-
elif "Malko Competition" in question:
|
71 |
-
return str("Dmitry")
|
72 |
-
else:
|
73 |
-
return "This is a default answer."
|
74 |
-
|
75 |
-
def extract_albums(self, wiki_text: str) -> list:
|
76 |
-
lines = wiki_text.split("\n")
|
77 |
-
albums = [line.strip() for line in lines if "-" in line]
|
78 |
-
return albums
|
79 |
|
80 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
81 |
"""
|
@@ -204,9 +153,11 @@ with gr.Blocks() as demo:
|
|
204 |
gr.Markdown(
|
205 |
"""
|
206 |
**Instructions:**
|
|
|
207 |
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
208 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
209 |
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
|
|
210 |
---
|
211 |
**Disclaimers:**
|
212 |
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).
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from langchain_core.messages import HumanMessage
|
7 |
+
from agent import build_graph
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# --- Basic Agent Definition ---
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
class BasicAgent:
|
16 |
def __init__(self):
|
|
|
17 |
print("BasicAgent initialized.")
|
18 |
+
self.graph = build_graph()
|
19 |
|
20 |
def __call__(self, question: str) -> str:
|
21 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
22 |
+
# Wrap the question in a HumanMessage from langchain_core
|
23 |
+
messages = [HumanMessage(content=question)]
|
24 |
+
messages = self.graph.invoke({"messages": messages})
|
25 |
+
answer = messages['messages'][-1].content
|
26 |
+
return answer[14:]
|
27 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
30 |
"""
|
|
|
153 |
gr.Markdown(
|
154 |
"""
|
155 |
**Instructions:**
|
156 |
+
|
157 |
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
158 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
159 |
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
160 |
+
|
161 |
---
|
162 |
**Disclaimers:**
|
163 |
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).
|