Idealcom commited on
Commit
de3cdff
·
verified ·
1 Parent(s): fc8afe5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -5
app.py CHANGED
@@ -4,10 +4,8 @@ import time
4
  from smolagents import (
5
  CodeAgent,
6
  DuckDuckGoSearchTool,
7
- InferenceClientModel,
8
- Tool,
9
- TransformersModel
10
-
11
  )
12
  from smolagents import VisitWebpageTool
13
 
@@ -19,10 +17,12 @@ class FinalAnswerTool(Tool):
19
  description = "Provides a final answer to the given problem."
20
  inputs = {"answer": {"type": "string", "description": "The final answer"}}
21
  output_type = "string"
 
22
  def forward(self, answer: str) -> str:
23
  return answer
24
 
25
  final_answer = FinalAnswerTool()
 
26
  model = TransformersModel(
27
  model_id="HuggingFaceTB/SmolLM-1B-Instruct",
28
  device_map="auto"
@@ -65,4 +65,40 @@ def run_evaluation_and_submit():
65
  try:
66
  result = agent.run(q["question"])
67
  ans = str(result).replace("FINAL ANSWER:", "").strip()
68
- answers.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  from smolagents import (
5
  CodeAgent,
6
  DuckDuckGoSearchTool,
7
+ Tool,
8
+ TransformersModel
 
 
9
  )
10
  from smolagents import VisitWebpageTool
11
 
 
17
  description = "Provides a final answer to the given problem."
18
  inputs = {"answer": {"type": "string", "description": "The final answer"}}
19
  output_type = "string"
20
+
21
  def forward(self, answer: str) -> str:
22
  return answer
23
 
24
  final_answer = FinalAnswerTool()
25
+
26
  model = TransformersModel(
27
  model_id="HuggingFaceTB/SmolLM-1B-Instruct",
28
  device_map="auto"
 
65
  try:
66
  result = agent.run(q["question"])
67
  ans = str(result).replace("FINAL ANSWER:", "").strip()
68
+ answers.append({"task_id": q["task_id"], "submitted_answer": ans})
69
+ logs += f"✅ {ans}\n\n"
70
+ except Exception as e:
71
+ logs += f"⚠️ Erreur: {e}\n\n"
72
+ answers.append({"task_id": q["task_id"], "submitted_answer": "Error"})
73
+
74
+ yield logs
75
+ time.sleep(0.2)
76
+
77
+ logs += "📤 Envoi au serveur...\n"
78
+ yield logs
79
+
80
+ try:
81
+ res = requests.post(
82
+ f"{API_URL}/submit",
83
+ json={"username": USERNAME, "agent_code": SPACE_URL, "answers": answers}
84
+ ).json()
85
+
86
+ logs += f"\n🎉 SCORE: {res.get('score', '?')}/{res.get('total', 20)}\n"
87
+ logs += f"📊 {res.get('percentage', '?')}%\n"
88
+
89
+ if res.get('percentage', 0) >= 30:
90
+ logs += "\n✅ BRAVO! ≥ 30%!\n"
91
+ logs += "Certificat: https://huggingface.co/spaces/agents-course/Unit4-Final-Certificate"
92
+ except Exception as e:
93
+ logs += f"\n❌ Erreur envoi: {e}"
94
+
95
+ yield logs
96
+
97
+ with gr.Blocks() as demo:
98
+ gr.Markdown("# 🎓 GAIA Agent - Examen Final")
99
+ btn = gr.Button("🚀 LANCER L'EXAMEN", variant="primary", size="lg")
100
+ logs = gr.Textbox(label="Logs", lines=30, interactive=False)
101
+ btn.click(run_evaluation_and_submit, outputs=logs)
102
+
103
+ if __name__ == "__main__":
104
+ demo.launch()