Psiska commited on
Commit
960dd3f
·
1 Parent(s): d001a5c
Files changed (2) hide show
  1. README.md +0 -1
  2. app.py +46 -38
README.md CHANGED
@@ -12,7 +12,6 @@ short_description: Multi-Agent Multi-Modal Multi-Model AI Platform
12
  tags:
13
  - agent-demo-track
14
  - mcp-server-track
15
- hf_oauth: true
16
  ---
17
 
18
 
 
12
  tags:
13
  - agent-demo-track
14
  - mcp-server-track
 
15
  ---
16
 
17
 
app.py CHANGED
@@ -2,90 +2,98 @@ import os
2
  import requests
3
  import pandas as pd
4
  import gradio as gr
5
- from crew import run_crew # <-- ο multi-agent κώδικας σου
6
 
7
- API_URL = "https://agents-course-unit4-scoring.hf.space" # endpoint αξιολόγησης
8
 
9
 
10
- # ------------------------- Agent Wrapper ------------------------- #
11
  class CrewAgent:
12
- """Καλεί το run_crew και επιστρέφει την απάντηση."""
13
  def __call__(self, question: str) -> str:
14
- return run_crew(question, file_path="") # δεν περνάμε file στην αξιολόγηση
15
-
16
 
17
  agent = CrewAgent()
18
 
19
 
20
- # ------------------------ Main Submit Fn ------------------------- #
21
- def evaluate_and_submit():
22
- """Τρέχει τον agent σε όλα τα benchmark Qs & στέλνει υποβολή."""
23
- username = os.getenv("HF_SPACE_USER")
24
  if not username:
25
- return "❌ Πρέπει να είστε συνδεδεμένος στο Hugging Face.", None
26
 
27
  space_id = os.getenv("SPACE_ID", "")
28
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else ""
29
 
30
- # 1. Φέρνουμε τις ερωτήσεις
31
  try:
32
  questions = requests.get(f"{API_URL}/questions", timeout=30).json()
33
  except Exception as e:
34
- return f"❌ Αποτυχία λήψης ερωτήσεων: {e}", None
35
 
36
- # 2. Απαντάμε
37
  answers, log = [], []
38
  for item in questions:
39
- qid, qtext = item["task_id"], item["question"]
40
  try:
41
- ans = agent(qtext)
 
 
 
 
 
42
  except Exception as e:
43
  ans = f"AGENT ERROR: {e}"
 
44
  answers.append({"task_id": qid, "submitted_answer": ans})
45
- log.append({"Task ID": qid, "Question": qtext, "Answer": ans})
 
 
 
 
 
 
 
 
46
 
47
  if not answers:
48
- return "⚠️ Δεν δημιουργήθηκαν απαντήσεις.", pd.DataFrame(log)
49
 
50
- # 3. Υποβολή
51
  try:
52
  resp = requests.post(
53
  f"{API_URL}/submit",
54
- json={
55
- "username": username,
56
- "agent_code": agent_code,
57
- "answers": answers,
58
- },
59
- timeout=60
60
  )
61
  resp.raise_for_status()
62
- data = resp.json()
63
  status = (
64
- f"✅ Υποβολή επιτυχής!\n"
65
- f"Σκορ: {data.get('score')} % "
66
  f"({data.get('correct_count')}/{data.get('total_attempted')})\n"
67
- f"Μήνυμα: {data.get('message')}"
68
  )
69
  except Exception as e:
70
- status = f"❌ Αποτυχία υποβολής: {e}"
71
 
72
  return status, pd.DataFrame(log)
73
 
74
 
75
- # ------------------------ Gradio UI ------------------------------ #
 
76
  demo = gr.Interface(
77
  fn=evaluate_and_submit,
78
- inputs=[], # καμία είσοδος απ’ τον χρήστη
79
  outputs=[
80
- gr.Textbox(label="Κατάσταση", lines=6),
81
- gr.DataFrame(label="Απαντήσεις που υποβλήθηκαν")
82
  ],
83
  title="GAIA Agent Submission",
84
  description=(
85
- "Πατήστε το κουμπί για να τρέξετε τον agent σας "
86
- "σε όλα τα benchmark ερωτήματα και να στείλετε τις απαντήσεις."
87
- " Απαιτείται να είστε συνδεδεμένος στον λογαριασμό Hugging Face."
88
- )
89
  )
90
 
91
  if __name__ == "__main__":
 
2
  import requests
3
  import pandas as pd
4
  import gradio as gr
5
+ from crew import run_crew # your multi-agent logic
6
 
7
+ API_URL = "https://agents-course-unit4-scoring.hf.space"
8
 
9
 
10
+ # ─── AGENT WRAPPER ──────────────────────────────────────────────────────────────
11
  class CrewAgent:
 
12
  def __call__(self, question: str) -> str:
13
+ return run_crew(question, file_path="") # It MUST use your real crew logic!
 
14
 
15
  agent = CrewAgent()
16
 
17
 
18
+ # ─── MAIN HANDLER ───────────────────────────────────────────────────────────────
19
+ def evaluate_and_submit(username: str):
20
+ """Runs the agent on benchmark questions and submits answers, with debug logging."""
21
+ username = username.strip()
22
  if not username:
23
+ return "❌ Please enter your Hugging Face username.", None
24
 
25
  space_id = os.getenv("SPACE_ID", "")
26
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else ""
27
 
28
+ # 1) Fetch questions
29
  try:
30
  questions = requests.get(f"{API_URL}/questions", timeout=30).json()
31
  except Exception as e:
32
+ return f"❌ Failed to fetch questions: {e}", None
33
 
34
+ # 2) Answer questions, logging every result
35
  answers, log = [], []
36
  for item in questions:
37
+ qid, qtxt = item["task_id"], item["question"]
38
  try:
39
+ ans = agent(qtxt)
40
+ # Debug print:
41
+ print(f"QID: {qid} | Q: {qtxt[:60]}... | Agent Answer: {ans}")
42
+ # Add warning if placeholder detected
43
+ if ans.strip().lower() in ["this is a default answer.", "", "n/a"]:
44
+ print(f"⚠️ Warning: Agent returned a default/empty answer for QID {qid}.")
45
  except Exception as e:
46
  ans = f"AGENT ERROR: {e}"
47
+ print(f"⚠️ Agent error on QID {qid}: {e}")
48
  answers.append({"task_id": qid, "submitted_answer": ans})
49
+ log.append({"Task ID": qid, "Question": qtxt, "Answer": ans})
50
+
51
+ # Show part of the DataFrame in the console for debugging
52
+ try:
53
+ df = pd.DataFrame(log)
54
+ print("=== First 5 results ===")
55
+ print(df.head())
56
+ except Exception as e:
57
+ print(f"DataFrame print error: {e}")
58
 
59
  if not answers:
60
+ return "⚠️ No answers generated.", pd.DataFrame(log)
61
 
62
+ # 3) Submit
63
  try:
64
  resp = requests.post(
65
  f"{API_URL}/submit",
66
+ json={"username": username, "agent_code": agent_code, "answers": answers},
67
+ timeout=60,
 
 
 
 
68
  )
69
  resp.raise_for_status()
70
+ data = resp.json()
71
  status = (
72
+ "✅ Submission successful!\n"
73
+ f"Score: {data.get('score')} % "
74
  f"({data.get('correct_count')}/{data.get('total_attempted')})\n"
75
+ f"Message: {data.get('message')}"
76
  )
77
  except Exception as e:
78
+ status = f"❌ Submission failed: {e}"
79
 
80
  return status, pd.DataFrame(log)
81
 
82
 
83
+
84
+ # ─── GRADIO UI ────────────────────────────────────────────��─────────────────────
85
  demo = gr.Interface(
86
  fn=evaluate_and_submit,
87
+ inputs=gr.Textbox(label="Hugging Face username", placeholder="e.g. john-doe"),
88
  outputs=[
89
+ gr.Textbox(label="Status", lines=6),
90
+ gr.DataFrame(label="Submitted Answers"),
91
  ],
92
  title="GAIA Agent Submission",
93
  description=(
94
+ "Enter your Hugging Face username and click **Run Evaluation & Submit**. "
95
+ "The app will run your agent on all benchmark questions and send the answers."
96
+ ),
 
97
  )
98
 
99
  if __name__ == "__main__":