Refacto html
Browse files
app.py
CHANGED
|
@@ -144,20 +144,21 @@ custom_css = """
|
|
| 144 |
}
|
| 145 |
"""
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
<div class="logo-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/smolagents.png" alt="Smolagents logo">
|
| 156 |
-
</div>
|
| 157 |
-
<div class="logo-item">
|
| 158 |
-
<img src=src="https://github.com/e2b-dev/E2B/blob/main/readme-assets/logo-circle.png?raw=true" alt="e2b logo">
|
| 159 |
-
</div>
|
| 160 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
<div class="sandbox-outer-wrapper">
|
| 162 |
<div class="sandbox-container">
|
| 163 |
<img src="https://huggingface.co/datasets/mfarre/servedfiles/resolve/main/desktop2.png" class="sandbox-background" />
|
|
@@ -408,16 +409,16 @@ def update_html(interactive_mode, request: gr.Request):
|
|
| 408 |
|
| 409 |
creation_time = SANDBOX_METADATA[session_hash]['created_at'] if session_hash in SANDBOX_METADATA else time.time()
|
| 410 |
|
| 411 |
-
|
| 412 |
stream_url=stream_url,
|
| 413 |
status_class=status_class,
|
| 414 |
status_text=status_text,
|
| 415 |
)
|
| 416 |
|
| 417 |
# Add hidden field with creation time for JavaScript to use
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
return
|
| 421 |
|
| 422 |
def generate_interaction_id(request):
|
| 423 |
"""Generate a unique ID combining session hash and timestamp"""
|
|
@@ -536,8 +537,13 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 536 |
#Storing session hash in a state variable
|
| 537 |
session_hash_state = gr.State(None)
|
| 538 |
|
| 539 |
-
|
| 540 |
-
value=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
stream_url="",
|
| 542 |
status_class="status-interactive",
|
| 543 |
status_text="Interactive"
|
|
@@ -640,7 +646,7 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 640 |
view_only_event = update_btn.click(
|
| 641 |
fn=clear_and_set_view_only,
|
| 642 |
inputs=[task_input],
|
| 643 |
-
outputs=[results_output,
|
| 644 |
).then(
|
| 645 |
agent_ui.log_user_message,
|
| 646 |
[task_input],
|
|
@@ -657,13 +663,13 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 657 |
).then(
|
| 658 |
fn=check_and_set_interactive,
|
| 659 |
inputs=[results_output],
|
| 660 |
-
outputs=
|
| 661 |
)
|
| 662 |
|
| 663 |
demo.load(
|
| 664 |
fn=initialize_session,
|
| 665 |
inputs=[gr.Checkbox(value=True, visible=False)],
|
| 666 |
-
outputs=[
|
| 667 |
)
|
| 668 |
|
| 669 |
# Connect refresh button to update terminal
|
|
|
|
| 144 |
}
|
| 145 |
"""
|
| 146 |
|
| 147 |
+
header_html="""
|
| 148 |
+
<h2 style="text-align: center">Personal Computer Assistant</h2>
|
| 149 |
+
<div class="logo-container">
|
| 150 |
+
<div class="logo-item">
|
| 151 |
+
<img src="https://upload.wikimedia.org/wikipedia/en/8/85/Logo_of_Qwen.png" alt="Qwen logo">
|
| 152 |
+
</div>
|
| 153 |
+
<div class="logo-item">
|
| 154 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/smolagents.png" alt="Smolagents logo">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
</div>
|
| 156 |
+
<div class="logo-item">
|
| 157 |
+
<img src=src="https://github.com/e2b-dev/E2B/blob/main/readme-assets/logo-circle.png?raw=true" alt="e2b logo">
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
"""
|
| 161 |
+
sandbox_html_template = """
|
| 162 |
<div class="sandbox-outer-wrapper">
|
| 163 |
<div class="sandbox-container">
|
| 164 |
<img src="https://huggingface.co/datasets/mfarre/servedfiles/resolve/main/desktop2.png" class="sandbox-background" />
|
|
|
|
| 409 |
|
| 410 |
creation_time = SANDBOX_METADATA[session_hash]['created_at'] if session_hash in SANDBOX_METADATA else time.time()
|
| 411 |
|
| 412 |
+
sandbox_html_content = sandbox_html_template.format(
|
| 413 |
stream_url=stream_url,
|
| 414 |
status_class=status_class,
|
| 415 |
status_text=status_text,
|
| 416 |
)
|
| 417 |
|
| 418 |
# Add hidden field with creation time for JavaScript to use
|
| 419 |
+
sandbox_html_content += f'<div id="sandbox-creation-time" style="display:none;" data-time="{creation_time}" data-timeout="{SANDBOX_TIMEOUT}"></div>'
|
| 420 |
+
|
| 421 |
+
return sandbox_html_content
|
| 422 |
|
| 423 |
def generate_interaction_id(request):
|
| 424 |
"""Generate a unique ID combining session hash and timestamp"""
|
|
|
|
| 537 |
#Storing session hash in a state variable
|
| 538 |
session_hash_state = gr.State(None)
|
| 539 |
|
| 540 |
+
header_html = gr.HTML(
|
| 541 |
+
value=header_html,
|
| 542 |
+
label="Header"
|
| 543 |
+
)
|
| 544 |
+
|
| 545 |
+
sandbox_html = gr.HTML(
|
| 546 |
+
value=sandbox_html_template.format(
|
| 547 |
stream_url="",
|
| 548 |
status_class="status-interactive",
|
| 549 |
status_text="Interactive"
|
|
|
|
| 646 |
view_only_event = update_btn.click(
|
| 647 |
fn=clear_and_set_view_only,
|
| 648 |
inputs=[task_input],
|
| 649 |
+
outputs=[results_output, sandbox_html, results_container]
|
| 650 |
).then(
|
| 651 |
agent_ui.log_user_message,
|
| 652 |
[task_input],
|
|
|
|
| 663 |
).then(
|
| 664 |
fn=check_and_set_interactive,
|
| 665 |
inputs=[results_output],
|
| 666 |
+
outputs=sandbox_html
|
| 667 |
)
|
| 668 |
|
| 669 |
demo.load(
|
| 670 |
fn=initialize_session,
|
| 671 |
inputs=[gr.Checkbox(value=True, visible=False)],
|
| 672 |
+
outputs=[sandbox_html, session_hash_state]
|
| 673 |
)
|
| 674 |
|
| 675 |
# Connect refresh button to update terminal
|