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