Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Miquel Farré
commited on
Commit
·
0d3c6ab
1
Parent(s):
32efaf3
new screen size + fixed interactive / view only
Browse files
app.py
CHANGED
@@ -16,8 +16,8 @@ E2B_API_KEY = os.getenv("E2B_API_KEY")
|
|
16 |
SANDBOXES = {}
|
17 |
SANDBOX_METADATA = {}
|
18 |
SANDBOX_TIMEOUT = 300
|
19 |
-
WIDTH =
|
20 |
-
HEIGHT =
|
21 |
TMP_DIR = './tmp/'
|
22 |
if not os.path.exists(TMP_DIR):
|
23 |
os.makedirs(TMP_DIR)
|
@@ -56,11 +56,11 @@ custom_css = """
|
|
56 |
position: absolute;
|
57 |
top: 10%;
|
58 |
left: 25%;
|
59 |
-
width:
|
60 |
-
height:
|
61 |
border: 4px solid #444444;
|
62 |
transform-origin: 0 0;
|
63 |
-
transform: scale(0.
|
64 |
}
|
65 |
|
66 |
/* Status indicator light */
|
@@ -345,7 +345,7 @@ def save_final_status(folder, status, details = None):
|
|
345 |
a.write(json.dumps({"status":status,"details":str(details)}))
|
346 |
a.close()
|
347 |
|
348 |
-
def run_agent_task(task_input,
|
349 |
session_hash = request.session_hash
|
350 |
interaction_id = generate_interaction_id(request)
|
351 |
desktop = get_or_create_sandbox(session_hash)
|
@@ -382,29 +382,26 @@ def run_agent_task(task_input, interactive_mode, request: gr.Request):
|
|
382 |
""")
|
383 |
|
384 |
try:
|
|
|
385 |
# Run the agent
|
386 |
result = agent.run(full_task)
|
387 |
-
save_final_status(data_dir, "completed", details = result)
|
388 |
-
|
389 |
-
|
390 |
-
return f"Task completed: {result}", update_html(interactive_mode, request)
|
391 |
except Exception as e:
|
392 |
error_message = f"Error running agent: {str(e)} Details {traceback.format_exc()}"
|
393 |
save_final_status(data_dir, "failed", details = error_message)
|
394 |
-
|
395 |
print(error_message)
|
396 |
-
interactive_mode = True
|
397 |
-
# return error_message, update_html(interactive_mode, request)
|
398 |
return error_message
|
|
|
399 |
finally:
|
400 |
upload_to_hf_and_remove(data_dir)
|
401 |
|
402 |
-
|
403 |
# Create a Gradio app with Blocks
|
404 |
with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
405 |
gr.HTML("""<h1 style="text-align: center">Personal Computer Assistant</h1>""")
|
406 |
|
407 |
-
# HTML output with simulated image and iframe
|
408 |
html_output = gr.HTML(
|
409 |
value=html_template.format(
|
410 |
stream_url="",
|
@@ -420,12 +417,6 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
420 |
label="Enter your command"
|
421 |
)
|
422 |
|
423 |
-
# Interactive mode checkbox
|
424 |
-
interactive_mode = gr.Checkbox(
|
425 |
-
value=False,
|
426 |
-
label="Interactive Mode"
|
427 |
-
)
|
428 |
-
|
429 |
# Results output
|
430 |
results_output = gr.Textbox(
|
431 |
label="Results",
|
@@ -436,22 +427,42 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
436 |
# Update button
|
437 |
update_btn = gr.Button("Let's go!")
|
438 |
|
439 |
-
#
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
)
|
445 |
|
446 |
-
#
|
447 |
-
|
448 |
fn=run_agent_task,
|
449 |
-
inputs=[task_input
|
450 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
)
|
452 |
-
|
453 |
-
# Load the sandbox on app start
|
454 |
-
demo.load(update_html, [interactive_mode], html_output)
|
455 |
|
456 |
# Launch the app
|
457 |
if __name__ == "__main__":
|
|
|
16 |
SANDBOXES = {}
|
17 |
SANDBOX_METADATA = {}
|
18 |
SANDBOX_TIMEOUT = 300
|
19 |
+
WIDTH = 1280
|
20 |
+
HEIGHT = 960
|
21 |
TMP_DIR = './tmp/'
|
22 |
if not os.path.exists(TMP_DIR):
|
23 |
os.makedirs(TMP_DIR)
|
|
|
56 |
position: absolute;
|
57 |
top: 10%;
|
58 |
left: 25%;
|
59 |
+
width: 1288px;
|
60 |
+
height: 968px;
|
61 |
border: 4px solid #444444;
|
62 |
transform-origin: 0 0;
|
63 |
+
transform: scale(0.312);
|
64 |
}
|
65 |
|
66 |
/* Status indicator light */
|
|
|
345 |
a.write(json.dumps({"status":status,"details":str(details)}))
|
346 |
a.close()
|
347 |
|
348 |
+
def run_agent_task(task_input, request: gr.Request):
|
349 |
session_hash = request.session_hash
|
350 |
interaction_id = generate_interaction_id(request)
|
351 |
desktop = get_or_create_sandbox(session_hash)
|
|
|
382 |
""")
|
383 |
|
384 |
try:
|
385 |
+
|
386 |
# Run the agent
|
387 |
result = agent.run(full_task)
|
388 |
+
save_final_status(data_dir, "completed", details = result)
|
389 |
+
return f"Task completed: {result}"
|
390 |
+
|
|
|
391 |
except Exception as e:
|
392 |
error_message = f"Error running agent: {str(e)} Details {traceback.format_exc()}"
|
393 |
save_final_status(data_dir, "failed", details = error_message)
|
|
|
394 |
print(error_message)
|
|
|
|
|
395 |
return error_message
|
396 |
+
|
397 |
finally:
|
398 |
upload_to_hf_and_remove(data_dir)
|
399 |
|
|
|
400 |
# Create a Gradio app with Blocks
|
401 |
with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
402 |
gr.HTML("""<h1 style="text-align: center">Personal Computer Assistant</h1>""")
|
403 |
|
404 |
+
# HTML output with simulated image and iframe - default to interactive
|
405 |
html_output = gr.HTML(
|
406 |
value=html_template.format(
|
407 |
stream_url="",
|
|
|
417 |
label="Enter your command"
|
418 |
)
|
419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
# Results output
|
421 |
results_output = gr.Textbox(
|
422 |
label="Results",
|
|
|
427 |
# Update button
|
428 |
update_btn = gr.Button("Let's go!")
|
429 |
|
430 |
+
# Function to set view-only mode
|
431 |
+
def set_view_only(task_input, request: gr.Request):
|
432 |
+
return update_html(False, request)
|
433 |
+
|
434 |
+
# Function to set interactive mode
|
435 |
+
def set_interactive_mode(request: gr.Request):
|
436 |
+
return update_html(True, request)
|
437 |
+
|
438 |
+
# Chain the events
|
439 |
+
# 1. Set view-only mode when button is clicked
|
440 |
+
view_only_event = update_btn.click(
|
441 |
+
fn=set_view_only,
|
442 |
+
inputs=[task_input],
|
443 |
+
outputs=html_output
|
444 |
)
|
445 |
|
446 |
+
# 2. Then run the agent task
|
447 |
+
task_result = view_only_event.then(
|
448 |
fn=run_agent_task,
|
449 |
+
inputs=[task_input],
|
450 |
+
outputs=results_output
|
451 |
+
)
|
452 |
+
|
453 |
+
# 3. Then set back to interactive mode
|
454 |
+
task_result.then(
|
455 |
+
fn=set_interactive_mode,
|
456 |
+
inputs=None, # No inputs needed here
|
457 |
+
outputs=html_output
|
458 |
+
)
|
459 |
+
|
460 |
+
# Load the sandbox on app start with initial HTML
|
461 |
+
demo.load(
|
462 |
+
fn=update_html,
|
463 |
+
inputs=[gr.Checkbox(value=True, visible=False)], # Hidden checkbox with True value
|
464 |
+
outputs=html_output
|
465 |
)
|
|
|
|
|
|
|
466 |
|
467 |
# Launch the app
|
468 |
if __name__ == "__main__":
|