Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Fix upload logic
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ from scripts_and_styling import (
|
|
30 |
load_dotenv(override=True)
|
31 |
|
32 |
|
33 |
-
|
34 |
"Use Google Maps to find the Hugging Face HQ in Paris",
|
35 |
"Go to Wikipedia and find what happened on April 4th",
|
36 |
"Find out the travel time by train from Bern to Basel on Google Maps",
|
@@ -63,14 +63,22 @@ def upload_to_hf_and_remove(folder_paths: list[str]):
|
|
63 |
repo_id = "smolagents/computer-agent-logs-2"
|
64 |
|
65 |
with tempfile.TemporaryDirectory(dir=TMP_DIR) as temp_dir:
|
66 |
-
print(
|
|
|
|
|
67 |
|
68 |
# Copy all folders into the temporary directory
|
69 |
for folder_path in folder_paths:
|
70 |
folder_name = os.path.basename(os.path.normpath(folder_path))
|
71 |
target_path = os.path.join(temp_dir, folder_name)
|
72 |
-
print(
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Remove the original folder after copying
|
75 |
shutil.rmtree(folder_path)
|
76 |
print(f"Original folder {folder_path} removed.")
|
@@ -263,6 +271,9 @@ class EnrichedGradioUI(GradioUI):
|
|
263 |
# Always re-create an agent from scratch, else Qwen-VL gets confused with past history
|
264 |
session_state["agent"] = create_agent(data_dir=data_dir, desktop=desktop)
|
265 |
|
|
|
|
|
|
|
266 |
try:
|
267 |
stored_messages.append(
|
268 |
gr.ChatMessage(
|
@@ -335,11 +346,10 @@ class EnrichedGradioUI(GradioUI):
|
|
335 |
status = "failed"
|
336 |
yield stored_messages
|
337 |
finally:
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
)
|
343 |
|
344 |
|
345 |
theme = gr.themes.Default(
|
@@ -378,7 +388,7 @@ _Please note that we store the task logs by default so **do not write any person
|
|
378 |
run_btn = gr.Button("Let's go!", variant="primary")
|
379 |
|
380 |
gr.Examples(
|
381 |
-
examples=
|
382 |
inputs=task_input,
|
383 |
label="Example Tasks",
|
384 |
examples_per_page=4,
|
|
|
30 |
load_dotenv(override=True)
|
31 |
|
32 |
|
33 |
+
TASK_EXAMPLES = [
|
34 |
"Use Google Maps to find the Hugging Face HQ in Paris",
|
35 |
"Go to Wikipedia and find what happened on April 4th",
|
36 |
"Find out the travel time by train from Bern to Basel on Google Maps",
|
|
|
63 |
repo_id = "smolagents/computer-agent-logs-2"
|
64 |
|
65 |
with tempfile.TemporaryDirectory(dir=TMP_DIR) as temp_dir:
|
66 |
+
print(
|
67 |
+
f"Uploading {len(folder_paths)} folders to {repo_id} (might end up with 0 folders uploaded if tasks are all examples)..."
|
68 |
+
)
|
69 |
|
70 |
# Copy all folders into the temporary directory
|
71 |
for folder_path in folder_paths:
|
72 |
folder_name = os.path.basename(os.path.normpath(folder_path))
|
73 |
target_path = os.path.join(temp_dir, folder_name)
|
74 |
+
print("Scanning folder", os.path.join(folder_path, "metadata.jsonl"))
|
75 |
+
if os.path.exists(os.path.join(folder_path, "metadata.jsonl")):
|
76 |
+
with open(os.path.join(folder_path, "metadata.jsonl"), "r") as f:
|
77 |
+
json_content = [json.loads(line) for line in f]
|
78 |
+
# Skip upload if the task is in the examples
|
79 |
+
if json_content[0]["task"] not in TASK_EXAMPLES:
|
80 |
+
print(f"Copying {folder_path} to temporary directory...")
|
81 |
+
shutil.copytree(folder_path, target_path)
|
82 |
# Remove the original folder after copying
|
83 |
shutil.rmtree(folder_path)
|
84 |
print(f"Original folder {folder_path} removed.")
|
|
|
271 |
# Always re-create an agent from scratch, else Qwen-VL gets confused with past history
|
272 |
session_state["agent"] = create_agent(data_dir=data_dir, desktop=desktop)
|
273 |
|
274 |
+
if not task_input or len(task_input) == 0:
|
275 |
+
raise gr.Error("Task cannot be empty")
|
276 |
+
|
277 |
try:
|
278 |
stored_messages.append(
|
279 |
gr.ChatMessage(
|
|
|
346 |
status = "failed"
|
347 |
yield stored_messages
|
348 |
finally:
|
349 |
+
summary = get_agent_summary_erase_images(session_state["agent"])
|
350 |
+
save_final_status(
|
351 |
+
data_dir, status, summary=summary, error_message=error_message
|
352 |
+
)
|
|
|
353 |
|
354 |
|
355 |
theme = gr.themes.Default(
|
|
|
388 |
run_btn = gr.Button("Let's go!", variant="primary")
|
389 |
|
390 |
gr.Examples(
|
391 |
+
examples=TASK_EXAMPLES,
|
392 |
inputs=task_input,
|
393 |
label="Example Tasks",
|
394 |
examples_per_page=4,
|