Idealcom commited on
Commit
3e0a65f
·
verified ·
1 Parent(s): daa93cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -4,13 +4,13 @@ import requests
4
  from smolagents import (
5
  CodeAgent,
6
  DuckDuckGoSearchTool,
7
- HuggingFaceHubModel,
8
  Tool
9
  )
10
  from smolagents import VisitWebpageTool
11
 
12
  # ==============================================================================
13
- # 1. TES INFORMATIONS (NE TOUCHE À RIEN ICI)
14
  # ==============================================================================
15
  USERNAME = "Idealcom"
16
  SPACE_URL = "https://huggingface.co/spaces/Idealcom/Final_Assignment_Template"
@@ -18,7 +18,6 @@ SPACE_URL = "https://huggingface.co/spaces/Idealcom/Final_Assignment_Template"
18
  # ==============================================================================
19
  # 2. CONFIGURATION DE L'AGENT
20
  # ==============================================================================
21
- # Outil de réponse
22
  class FinalAnswerTool(Tool):
23
  name = "final_answer"
24
  description = "Provides a final answer to the given problem."
@@ -31,14 +30,11 @@ final_answer = FinalAnswerTool()
31
  web_search = DuckDuckGoSearchTool()
32
  visit_webpage = VisitWebpageTool()
33
 
34
- # Le Modèle (Cerveau)
35
- # Grâce à la mise à jour requirements, cette classe va enfin marcher !
36
  model = HuggingFaceHubModel(
37
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
38
  temperature=0.5,
39
  )
40
 
41
- # L'Agent
42
  agent = CodeAgent(
43
  model=model,
44
  tools=[web_search, visit_webpage, final_answer],
@@ -49,7 +45,7 @@ agent = CodeAgent(
49
  )
50
 
51
  # ==============================================================================
52
- # 3. LE MOTEUR D'EXAMEN & SOUMISSION
53
  # ==============================================================================
54
  API_URL = "https://agents-course-unit4-scoring.hf.space"
55
 
@@ -57,19 +53,17 @@ def run_evaluation_and_submit():
57
  logs = "🚀 DÉBUT DE L'EXAMEN...\n"
58
  yield logs
59
 
60
- # 1. Récupération des questions
61
  try:
62
  response = requests.get(f"{API_URL}/questions")
63
  questions = response.json()
64
  logs += f"📚 {len(questions)} questions chargées.\n\n"
65
  yield logs
66
  except Exception as e:
67
- yield f"❌ Erreur connexion serveur : {e}"
68
  return
69
 
70
  answers = []
71
 
72
- # 2. L'agent résout les questions
73
  for i, q in enumerate(questions, 1):
74
  logs += f"🔹 Question {i}/{len(questions)} : {q['question']}\n"
75
  yield logs
@@ -90,8 +84,8 @@ def run_evaluation_and_submit():
90
 
91
  yield logs
92
 
93
- # 3. Envoi des résultats
94
- logs += "📤 Envoi des notes au juge...\n"
95
  yield logs
96
 
97
  try:
@@ -112,14 +106,14 @@ def run_evaluation_and_submit():
112
  yield logs
113
 
114
  # ==============================================================================
115
- # 4. INTERFACE
116
  # ==============================================================================
117
  with gr.Blocks() as demo:
118
- gr.Markdown("# 🎓 Certification GAIA Agent")
119
  gr.Markdown("Clique sur le bouton pour lancer l'examen.")
120
 
121
  btn = gr.Button("🚀 LANCER L'EXAMEN & SOUMETTRE", variant="primary")
122
- logs = gr.Textbox(label="Journal de bord", lines=25)
123
 
124
  btn.click(run_evaluation_and_submit, outputs=logs)
125
 
 
4
  from smolagents import (
5
  CodeAgent,
6
  DuckDuckGoSearchTool,
7
+ HuggingFaceHubModel,
8
  Tool
9
  )
10
  from smolagents import VisitWebpageTool
11
 
12
  # ==============================================================================
13
+ # 1. INFOS
14
  # ==============================================================================
15
  USERNAME = "Idealcom"
16
  SPACE_URL = "https://huggingface.co/spaces/Idealcom/Final_Assignment_Template"
 
18
  # ==============================================================================
19
  # 2. CONFIGURATION DE L'AGENT
20
  # ==============================================================================
 
21
  class FinalAnswerTool(Tool):
22
  name = "final_answer"
23
  description = "Provides a final answer to the given problem."
 
30
  web_search = DuckDuckGoSearchTool()
31
  visit_webpage = VisitWebpageTool()
32
 
 
 
33
  model = HuggingFaceHubModel(
34
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
35
  temperature=0.5,
36
  )
37
 
 
38
  agent = CodeAgent(
39
  model=model,
40
  tools=[web_search, visit_webpage, final_answer],
 
45
  )
46
 
47
  # ==============================================================================
48
+ # 3. Evaluation Runner
49
  # ==============================================================================
50
  API_URL = "https://agents-course-unit4-scoring.hf.space"
51
 
 
53
  logs = "🚀 DÉBUT DE L'EXAMEN...\n"
54
  yield logs
55
 
 
56
  try:
57
  response = requests.get(f"{API_URL}/questions")
58
  questions = response.json()
59
  logs += f"📚 {len(questions)} questions chargées.\n\n"
60
  yield logs
61
  except Exception as e:
62
+ yield f"❌ Erreur critique connexion serveur : {e}"
63
  return
64
 
65
  answers = []
66
 
 
67
  for i, q in enumerate(questions, 1):
68
  logs += f"🔹 Question {i}/{len(questions)} : {q['question']}\n"
69
  yield logs
 
84
 
85
  yield logs
86
 
87
+ # 3. Soumission
88
+ logs += "📤 Envoi des résultats...\n"
89
  yield logs
90
 
91
  try:
 
106
  yield logs
107
 
108
  # ==============================================================================
109
+ # 4. L'INTERFACE
110
  # ==============================================================================
111
  with gr.Blocks() as demo:
112
+ gr.Markdown("# 🎓 Certification GAIA")
113
  gr.Markdown("Clique sur le bouton pour lancer l'examen.")
114
 
115
  btn = gr.Button("🚀 LANCER L'EXAMEN & SOUMETTRE", variant="primary")
116
+ logs = gr.Textbox(label="Logs", lines=25)
117
 
118
  btn.click(run_evaluation_and_submit, outputs=logs)
119