Spaces:
Running
Running
terryyz
commited on
Commit
Β·
275e3c8
1
Parent(s):
1bb2113
update
Browse files- app.py +17 -13
- sandbox/code_runner.py +37 -8
- sandbox/prompts.py +3 -11
- sandbox/sandbox_manager.py +2 -0
- sandbox/sandbox_telemetry.py +2 -2
app.py
CHANGED
|
@@ -237,7 +237,7 @@ def extract_and_execute_code(message, sandbox_state):
|
|
| 237 |
return sandbox_state, "", ""
|
| 238 |
|
| 239 |
code, code_language, env_selection, install_command = extract_result
|
| 240 |
-
|
| 241 |
# Update sandbox state (now a dictionary)
|
| 242 |
sandbox_state['code_to_execute'] = code
|
| 243 |
sandbox_state['install_command'] = install_command
|
|
@@ -366,7 +366,7 @@ def add_text_and_generate(state0, state1, text, temperature, max_tokens, model_a
|
|
| 366 |
if sandbox_output0:
|
| 367 |
sandbox_view_a += sandbox_output0
|
| 368 |
if sandbox_error0:
|
| 369 |
-
sandbox_view_a = f"<details closed><summary><strong>π¨ Errors</strong></summary>\n\n```\n{sandbox_error0}\n```\n\n</details>\n\n" + sandbox_view_a
|
| 370 |
|
| 371 |
# Process results for model B
|
| 372 |
if code1.strip():
|
|
@@ -385,7 +385,7 @@ def add_text_and_generate(state0, state1, text, temperature, max_tokens, model_a
|
|
| 385 |
if sandbox_output1:
|
| 386 |
sandbox_view_b += sandbox_output1
|
| 387 |
if sandbox_error1:
|
| 388 |
-
sandbox_view_b = f"<details closed><summary><strong>π¨ Errors</strong></summary>\n\n```\n{sandbox_error1}\n```\n\n</details>\n\n" + sandbox_view_b
|
| 389 |
|
| 390 |
except Exception as e:
|
| 391 |
# Fallback to sequential processing
|
|
@@ -401,7 +401,7 @@ def add_text_and_generate(state0, state1, text, temperature, max_tokens, model_a
|
|
| 401 |
if sandbox_output0:
|
| 402 |
sandbox_view_a += sandbox_output0
|
| 403 |
if sandbox_error0:
|
| 404 |
-
sandbox_view_a = f"<details closed><summary><strong>π¨ Errors</strong></summary>\n\n```\n{sandbox_error0}\n```\n\n</details>\n\n" + sandbox_view_a
|
| 405 |
|
| 406 |
if code1.strip():
|
| 407 |
install_command1 = sandbox_state1.get('install_command', "")
|
|
@@ -415,7 +415,7 @@ def add_text_and_generate(state0, state1, text, temperature, max_tokens, model_a
|
|
| 415 |
if sandbox_output1:
|
| 416 |
sandbox_view_b += f"## Output\n{sandbox_output1}"
|
| 417 |
if sandbox_error1:
|
| 418 |
-
sandbox_view_b = f"<details closed><summary><strong>π¨ Errors</strong></summary>\n\n```\n{sandbox_error1}\n```\n\n</details>\n\n" + sandbox_view_b
|
| 419 |
|
| 420 |
sandbox_time = time.time() - sandbox_start_time
|
| 421 |
finally:
|
|
@@ -592,7 +592,7 @@ def retry_last_message(state0, state1, model_a, model_b):
|
|
| 592 |
result[19] if len(result) > 19 else "", # sandbox_view_b
|
| 593 |
new_state0, # state0_var
|
| 594 |
new_state1, # state1_var
|
| 595 |
-
|
| 596 |
f"**Model A:** {model_a}", # Update model display A
|
| 597 |
f"**Model B:** {model_b}", # Update model display B
|
| 598 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
@@ -652,7 +652,7 @@ def send_to_left_only(state0, state1, text, temperature, max_tokens, model_a, mo
|
|
| 652 |
if sandbox_output0:
|
| 653 |
sandbox_view_a += f"# Output\n{sandbox_output0}"
|
| 654 |
if sandbox_error0:
|
| 655 |
-
sandbox_view_a = f"<details closed><summary><strong>π¨ Errors</strong></summary>\n\n```\n{sandbox_error0.strip()}\n```\n\n</details>\n\n" + sandbox_view_a
|
| 656 |
|
| 657 |
# Calculate conversation statistics
|
| 658 |
turn_count_a = len([msg for msg in state0["messages"] if msg["role"] == "assistant" and msg["content"]])
|
|
@@ -685,7 +685,7 @@ def send_to_left_only(state0, state1, text, temperature, max_tokens, model_a, mo
|
|
| 685 |
"", # sandbox_view_b (empty)
|
| 686 |
state0, # state0_var
|
| 687 |
state1, # state1_var
|
| 688 |
-
|
| 689 |
f"**Model A:** {model_a}", # Update model display A
|
| 690 |
f"**Model B:** {model_b}", # Update model display B
|
| 691 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
@@ -745,7 +745,7 @@ def send_to_right_only(state0, state1, text, temperature, max_tokens, model_a, m
|
|
| 745 |
if sandbox_output1:
|
| 746 |
sandbox_view_b += f"# Output\n{sandbox_output1}"
|
| 747 |
if sandbox_error1:
|
| 748 |
-
sandbox_view_b = f"<details closed><summary><strong>π¨ Errors</strong></summary>\n\n```\n{sandbox_error1.strip()}\n```\n\n</details>\n\n" + sandbox_view_b
|
| 749 |
|
| 750 |
# Calculate conversation statistics
|
| 751 |
turn_count_a = len([msg for msg in state0["messages"] if msg["role"] == "assistant" and msg["content"]]) if state0 else 0
|
|
@@ -778,7 +778,7 @@ def send_to_right_only(state0, state1, text, temperature, max_tokens, model_a, m
|
|
| 778 |
sandbox_view_b, # sandbox_view_b
|
| 779 |
state0, # state0_var
|
| 780 |
state1, # state1_var
|
| 781 |
-
|
| 782 |
f"**Model A:** {model_a}", # Update model display A
|
| 783 |
f"**Model B:** {model_b}", # Update model display B
|
| 784 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
@@ -886,7 +886,7 @@ def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tu
|
|
| 886 |
|
| 887 |
# Determine environment
|
| 888 |
env = sandbox_state.get('auto_selected_sandbox_environment') or sandbox_state.get('sandbox_environment')
|
| 889 |
-
|
| 890 |
try:
|
| 891 |
if env == SandboxEnvironment.HTML:
|
| 892 |
sandbox_url, sandbox_id, stderr = run_html_sandbox(code, install_command, sandbox_state.get('sandbox_id'))
|
|
@@ -909,6 +909,7 @@ def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tu
|
|
| 909 |
return result['sandbox_url'], "", result['stderr']
|
| 910 |
|
| 911 |
elif env == SandboxEnvironment.GRADIO:
|
|
|
|
| 912 |
sandbox_url, sandbox_id, stderr = run_gradio_sandbox(code, install_command, sandbox_state.get('sandbox_id'))
|
| 913 |
sandbox_state['sandbox_id'] = sandbox_id
|
| 914 |
return sandbox_url, "", stderr
|
|
@@ -926,6 +927,7 @@ def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tu
|
|
| 926 |
return sandbox_url, "", stderr
|
| 927 |
|
| 928 |
elif env == SandboxEnvironment.PYTHON_RUNNER:
|
|
|
|
| 929 |
output, stderr = run_code_interpreter(code, 'python', install_command)
|
| 930 |
return "", output, stderr
|
| 931 |
|
|
@@ -1697,7 +1699,7 @@ def build_ui():
|
|
| 1697 |
result[19] if len(result) > 19 else "", # sandbox_view_b
|
| 1698 |
new_state0, # state0_var
|
| 1699 |
new_state1, # state1_var
|
| 1700 |
-
|
| 1701 |
f"**Model A:** {model_a}", # Update model display A
|
| 1702 |
f"**Model B:** {model_b}", # Update model display B
|
| 1703 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
@@ -2046,7 +2048,7 @@ def build_ui():
|
|
| 2046 |
# Get new random models
|
| 2047 |
model_a, model_b = get_random_models()
|
| 2048 |
|
| 2049 |
-
# Clear everything and start fresh immediately
|
| 2050 |
return (
|
| 2051 |
"Thank you for your vote! π", # vote status with thank you message
|
| 2052 |
None, # Clear state0
|
|
@@ -2075,6 +2077,7 @@ def build_ui():
|
|
| 2075 |
gr.update(interactive=False), # Disable vote_right_btn
|
| 2076 |
gr.update(interactive=False), # Disable vote_tie_btn
|
| 2077 |
gr.update(interactive=False), # Disable vote_both_bad_btn
|
|
|
|
| 2078 |
)
|
| 2079 |
|
| 2080 |
# Vote button click handlers
|
|
@@ -2115,6 +2118,7 @@ def build_ui():
|
|
| 2115 |
vote_right_btn, # vote_right_btn
|
| 2116 |
vote_tie_btn, # vote_tie_btn
|
| 2117 |
vote_both_bad_btn, # vote_both_bad_btn
|
|
|
|
| 2118 |
],
|
| 2119 |
)
|
| 2120 |
|
|
|
|
| 237 |
return sandbox_state, "", ""
|
| 238 |
|
| 239 |
code, code_language, env_selection, install_command = extract_result
|
| 240 |
+
|
| 241 |
# Update sandbox state (now a dictionary)
|
| 242 |
sandbox_state['code_to_execute'] = code
|
| 243 |
sandbox_state['install_command'] = install_command
|
|
|
|
| 366 |
if sandbox_output0:
|
| 367 |
sandbox_view_a += sandbox_output0
|
| 368 |
if sandbox_error0:
|
| 369 |
+
sandbox_view_a = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error0}\n```\n\n</details>\n\n" + sandbox_view_a
|
| 370 |
|
| 371 |
# Process results for model B
|
| 372 |
if code1.strip():
|
|
|
|
| 385 |
if sandbox_output1:
|
| 386 |
sandbox_view_b += sandbox_output1
|
| 387 |
if sandbox_error1:
|
| 388 |
+
sandbox_view_b = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error1}\n```\n\n</details>\n\n" + sandbox_view_b
|
| 389 |
|
| 390 |
except Exception as e:
|
| 391 |
# Fallback to sequential processing
|
|
|
|
| 401 |
if sandbox_output0:
|
| 402 |
sandbox_view_a += sandbox_output0
|
| 403 |
if sandbox_error0:
|
| 404 |
+
sandbox_view_a = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error0}\n```\n\n</details>\n\n" + sandbox_view_a
|
| 405 |
|
| 406 |
if code1.strip():
|
| 407 |
install_command1 = sandbox_state1.get('install_command', "")
|
|
|
|
| 415 |
if sandbox_output1:
|
| 416 |
sandbox_view_b += f"## Output\n{sandbox_output1}"
|
| 417 |
if sandbox_error1:
|
| 418 |
+
sandbox_view_b = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error1}\n```\n\n</details>\n\n" + sandbox_view_b
|
| 419 |
|
| 420 |
sandbox_time = time.time() - sandbox_start_time
|
| 421 |
finally:
|
|
|
|
| 592 |
result[19] if len(result) > 19 else "", # sandbox_view_b
|
| 593 |
new_state0, # state0_var
|
| 594 |
new_state1, # state1_var
|
| 595 |
+
last_user_message, # Keep original text input
|
| 596 |
f"**Model A:** {model_a}", # Update model display A
|
| 597 |
f"**Model B:** {model_b}", # Update model display B
|
| 598 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
|
|
| 652 |
if sandbox_output0:
|
| 653 |
sandbox_view_a += f"# Output\n{sandbox_output0}"
|
| 654 |
if sandbox_error0:
|
| 655 |
+
sandbox_view_a = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error0.strip()}\n```\n\n</details>\n\n" + sandbox_view_a
|
| 656 |
|
| 657 |
# Calculate conversation statistics
|
| 658 |
turn_count_a = len([msg for msg in state0["messages"] if msg["role"] == "assistant" and msg["content"]])
|
|
|
|
| 685 |
"", # sandbox_view_b (empty)
|
| 686 |
state0, # state0_var
|
| 687 |
state1, # state1_var
|
| 688 |
+
text, # Keep original text input
|
| 689 |
f"**Model A:** {model_a}", # Update model display A
|
| 690 |
f"**Model B:** {model_b}", # Update model display B
|
| 691 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
|
|
| 745 |
if sandbox_output1:
|
| 746 |
sandbox_view_b += f"# Output\n{sandbox_output1}"
|
| 747 |
if sandbox_error1:
|
| 748 |
+
sandbox_view_b = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error1.strip()}\n```\n\n</details>\n\n" + sandbox_view_b
|
| 749 |
|
| 750 |
# Calculate conversation statistics
|
| 751 |
turn_count_a = len([msg for msg in state0["messages"] if msg["role"] == "assistant" and msg["content"]]) if state0 else 0
|
|
|
|
| 778 |
sandbox_view_b, # sandbox_view_b
|
| 779 |
state0, # state0_var
|
| 780 |
state1, # state1_var
|
| 781 |
+
text, # Keep original text input
|
| 782 |
f"**Model A:** {model_a}", # Update model display A
|
| 783 |
f"**Model B:** {model_b}", # Update model display B
|
| 784 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
|
|
| 886 |
|
| 887 |
# Determine environment
|
| 888 |
env = sandbox_state.get('auto_selected_sandbox_environment') or sandbox_state.get('sandbox_environment')
|
| 889 |
+
print(f"DEBUG: env: {env}")
|
| 890 |
try:
|
| 891 |
if env == SandboxEnvironment.HTML:
|
| 892 |
sandbox_url, sandbox_id, stderr = run_html_sandbox(code, install_command, sandbox_state.get('sandbox_id'))
|
|
|
|
| 909 |
return result['sandbox_url'], "", result['stderr']
|
| 910 |
|
| 911 |
elif env == SandboxEnvironment.GRADIO:
|
| 912 |
+
print(f"DEBUG: running gradio sandbox")
|
| 913 |
sandbox_url, sandbox_id, stderr = run_gradio_sandbox(code, install_command, sandbox_state.get('sandbox_id'))
|
| 914 |
sandbox_state['sandbox_id'] = sandbox_id
|
| 915 |
return sandbox_url, "", stderr
|
|
|
|
| 927 |
return sandbox_url, "", stderr
|
| 928 |
|
| 929 |
elif env == SandboxEnvironment.PYTHON_RUNNER:
|
| 930 |
+
print(f"DEBUG: running python runner")
|
| 931 |
output, stderr = run_code_interpreter(code, 'python', install_command)
|
| 932 |
return "", output, stderr
|
| 933 |
|
|
|
|
| 1699 |
result[19] if len(result) > 19 else "", # sandbox_view_b
|
| 1700 |
new_state0, # state0_var
|
| 1701 |
new_state1, # state1_var
|
| 1702 |
+
text, # Keep original text input
|
| 1703 |
f"**Model A:** {model_a}", # Update model display A
|
| 1704 |
f"**Model B:** {model_b}", # Update model display B
|
| 1705 |
gr.update(visible=show_vote_buttons), # vote_section
|
|
|
|
| 2048 |
# Get new random models
|
| 2049 |
model_a, model_b = get_random_models()
|
| 2050 |
|
| 2051 |
+
# Clear everything and start fresh immediately, but preserve examples
|
| 2052 |
return (
|
| 2053 |
"Thank you for your vote! π", # vote status with thank you message
|
| 2054 |
None, # Clear state0
|
|
|
|
| 2077 |
gr.update(interactive=False), # Disable vote_right_btn
|
| 2078 |
gr.update(interactive=False), # Disable vote_tie_btn
|
| 2079 |
gr.update(interactive=False), # Disable vote_both_bad_btn
|
| 2080 |
+
"", # Clear text_input to preserve examples
|
| 2081 |
)
|
| 2082 |
|
| 2083 |
# Vote button click handlers
|
|
|
|
| 2118 |
vote_right_btn, # vote_right_btn
|
| 2119 |
vote_tie_btn, # vote_tie_btn
|
| 2120 |
vote_both_bad_btn, # vote_both_bad_btn
|
| 2121 |
+
text_input, # text_input (to preserve examples)
|
| 2122 |
],
|
| 2123 |
)
|
| 2124 |
|
sandbox/code_runner.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import Any, Generator, Literal, TypeAlias, TypedDict, Set
|
|
| 8 |
import uuid
|
| 9 |
import time
|
| 10 |
import gradio as gr
|
| 11 |
-
|
| 12 |
import base64
|
| 13 |
from e2b_code_interpreter import Sandbox as CodeSandbox
|
| 14 |
from gradio_sandboxcomponent import SandboxComponent
|
|
@@ -444,15 +444,19 @@ def run_html_sandbox(code: str, install_command: str, existing_sandbox_id: str |
|
|
| 444 |
sandbox.files.make_dir(project_root)
|
| 445 |
|
| 446 |
# Run install command if provided
|
|
|
|
| 447 |
if install_command.strip():
|
| 448 |
is_success, stdout, stderr = run_command_in_sandbox(
|
| 449 |
sandbox=sandbox,
|
| 450 |
command=install_command,
|
| 451 |
timeout=60 * 3,
|
| 452 |
)
|
|
|
|
|
|
|
| 453 |
if not is_success:
|
| 454 |
print(f"Install command failed: {stderr}")
|
| 455 |
-
return
|
|
|
|
| 456 |
|
| 457 |
# replace placeholder URLs with SVG data URLs
|
| 458 |
code = replace_placeholder_urls(code)
|
|
@@ -461,7 +465,7 @@ def run_html_sandbox(code: str, install_command: str, existing_sandbox_id: str |
|
|
| 461 |
sandbox.files.write(file_path, code, "user", 60)
|
| 462 |
|
| 463 |
sandbox_url = get_sandbox_app_url(sandbox, 'html')
|
| 464 |
-
return (sandbox_url, sandbox.sandbox_id, '')
|
| 465 |
|
| 466 |
|
| 467 |
def run_react_sandbox(code: str, install_command: str, existing_sandbox_id: str | None = None) -> CodeRunResult:
|
|
@@ -661,6 +665,30 @@ def run_gradio_sandbox(code: str, install_command: str, existing_sandbox_id: str
|
|
| 661 |
sandbox = reuse_or_create_sandbox(sandbox_id=existing_sandbox_id)
|
| 662 |
|
| 663 |
file_path = "~/gradio_app/main.py"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
sandbox.files.write(file_path, code, "user", 60)
|
| 665 |
|
| 666 |
stderrs = []
|
|
@@ -676,12 +704,12 @@ def run_gradio_sandbox(code: str, install_command: str, existing_sandbox_id: str
|
|
| 676 |
stderrs.extend(stderr)
|
| 677 |
if not is_success:
|
| 678 |
print(f"Install command failed: {stderr}")
|
| 679 |
-
return
|
| 680 |
-
|
| 681 |
stderr = run_background_command_with_timeout(
|
| 682 |
sandbox,
|
| 683 |
f"python {file_path}",
|
| 684 |
-
timeout=
|
| 685 |
)
|
| 686 |
stderrs.append(stderr)
|
| 687 |
|
|
@@ -710,12 +738,13 @@ def run_streamlit_sandbox(code: str, install_command: str, existing_sandbox_id:
|
|
| 710 |
stderrs.extend(stderr)
|
| 711 |
if not is_success:
|
| 712 |
print(f"Install command failed: {stderr}")
|
| 713 |
-
return
|
|
|
|
| 714 |
|
| 715 |
stderr = run_background_command_with_timeout(
|
| 716 |
sandbox,
|
| 717 |
r"sudo kill -9 $(ss -lptn 'sport = :8501' | grep -oP '(?<=pid=)\d+'); streamlit run ~/mystreamlit/app.py --server.port 8501 --server.headless true",
|
| 718 |
-
timeout=
|
| 719 |
)
|
| 720 |
stderrs.append(stderr)
|
| 721 |
|
|
|
|
| 8 |
import uuid
|
| 9 |
import time
|
| 10 |
import gradio as gr
|
| 11 |
+
import re
|
| 12 |
import base64
|
| 13 |
from e2b_code_interpreter import Sandbox as CodeSandbox
|
| 14 |
from gradio_sandboxcomponent import SandboxComponent
|
|
|
|
| 444 |
sandbox.files.make_dir(project_root)
|
| 445 |
|
| 446 |
# Run install command if provided
|
| 447 |
+
stderrs = []
|
| 448 |
if install_command.strip():
|
| 449 |
is_success, stdout, stderr = run_command_in_sandbox(
|
| 450 |
sandbox=sandbox,
|
| 451 |
command=install_command,
|
| 452 |
timeout=60 * 3,
|
| 453 |
)
|
| 454 |
+
if stderr:
|
| 455 |
+
stderrs.extend(stderr)
|
| 456 |
if not is_success:
|
| 457 |
print(f"Install command failed: {stderr}")
|
| 458 |
+
# Don't return early - continue with HTML setup
|
| 459 |
+
stderrs.append(f"Install command failed: {' '.join(stderr)}")
|
| 460 |
|
| 461 |
# replace placeholder URLs with SVG data URLs
|
| 462 |
code = replace_placeholder_urls(code)
|
|
|
|
| 465 |
sandbox.files.write(file_path, code, "user", 60)
|
| 466 |
|
| 467 |
sandbox_url = get_sandbox_app_url(sandbox, 'html')
|
| 468 |
+
return (sandbox_url, sandbox.sandbox_id, '\n'.join(stderrs))
|
| 469 |
|
| 470 |
|
| 471 |
def run_react_sandbox(code: str, install_command: str, existing_sandbox_id: str | None = None) -> CodeRunResult:
|
|
|
|
| 665 |
sandbox = reuse_or_create_sandbox(sandbox_id=existing_sandbox_id)
|
| 666 |
|
| 667 |
file_path = "~/gradio_app/main.py"
|
| 668 |
+
|
| 669 |
+
# Remove server_port and server_name arguments from demo.launch() calls
|
| 670 |
+
code = re.sub(r'\.launch\([^)]*server_port\s*=\s*[^,)]+[,\s]*', '.launch(', code)
|
| 671 |
+
code = re.sub(r'\.launch\([^)]*server_name\s*=\s*[^,)]+[,\s]*', '.launch(', code)
|
| 672 |
+
|
| 673 |
+
# Ensure demo.launch() uses the correct server configuration
|
| 674 |
+
if 'demo.launch(' in code:
|
| 675 |
+
# Replace demo.launch() with proper configuration
|
| 676 |
+
code = re.sub(
|
| 677 |
+
r'demo\.launch\([^)]*\)',
|
| 678 |
+
f'demo.launch(server_name="0.0.0.0", server_port=7860, share=False)',
|
| 679 |
+
code
|
| 680 |
+
)
|
| 681 |
+
elif '.launch(' in code:
|
| 682 |
+
# Handle other patterns like app.launch(), interface.launch(), etc.
|
| 683 |
+
code = re.sub(
|
| 684 |
+
r'(\w+)\.launch\([^)]*\)',
|
| 685 |
+
rf'\1.launch(server_name="0.0.0.0", server_port=7860, share=False)',
|
| 686 |
+
code
|
| 687 |
+
)
|
| 688 |
+
else:
|
| 689 |
+
# If no launch() call found, add one at the end
|
| 690 |
+
code += f'\n\n# Auto-added launch configuration\nif __name__ == "__main__":\n demo.launch(server_name="0.0.0.0", server_port=7860, share=False)'
|
| 691 |
+
|
| 692 |
sandbox.files.write(file_path, code, "user", 60)
|
| 693 |
|
| 694 |
stderrs = []
|
|
|
|
| 704 |
stderrs.extend(stderr)
|
| 705 |
if not is_success:
|
| 706 |
print(f"Install command failed: {stderr}")
|
| 707 |
+
# Don't return early - continue with Gradio setup
|
| 708 |
+
stderrs.append(f"Install command failed: {' '.join(stderr)}")
|
| 709 |
stderr = run_background_command_with_timeout(
|
| 710 |
sandbox,
|
| 711 |
f"python {file_path}",
|
| 712 |
+
timeout=15,
|
| 713 |
)
|
| 714 |
stderrs.append(stderr)
|
| 715 |
|
|
|
|
| 738 |
stderrs.extend(stderr)
|
| 739 |
if not is_success:
|
| 740 |
print(f"Install command failed: {stderr}")
|
| 741 |
+
# Don't return early - continue with Streamlit setup
|
| 742 |
+
stderrs.append(f"Install command failed: {' '.join(stderr)}")
|
| 743 |
|
| 744 |
stderr = run_background_command_with_timeout(
|
| 745 |
sandbox,
|
| 746 |
r"sudo kill -9 $(ss -lptn 'sport = :8501' | grep -oP '(?<=pid=)\d+'); streamlit run ~/mystreamlit/app.py --server.port 8501 --server.headless true",
|
| 747 |
+
timeout=15,
|
| 748 |
)
|
| 749 |
stderrs.append(stderr)
|
| 750 |
|
sandbox/prompts.py
CHANGED
|
@@ -28,18 +28,8 @@ The code must be in the markdown format:
|
|
| 28 |
```
|
| 29 |
|
| 30 |
Before you begin writing any code, you must follow these fundamental rules:
|
| 31 |
-
- You are NOT allowed to start directly with a code block. Before writing code, ALWAYS think carefully step-by-step
|
| 32 |
-
- Your response must contain a clear explanation of the solution you are providing
|
| 33 |
- ALWAYS generate complete, self-contained code in a single file
|
| 34 |
- You CAN NOT split your program into multiple files or multiple code blocks
|
| 35 |
-
- If you use any external libraries, make sure to specify them for the installation command in either `pip install` or `npm install`
|
| 36 |
-
- You prefer JavaScript over HTML
|
| 37 |
-
- Each code block must be completely independent. If modifications are needed, the entire code block must be rewritten
|
| 38 |
-
- When fetching data, you MUST use external libraries and packages, and avoid using placeholder URLs or URLs that require API keys
|
| 39 |
-
- Make sure the program is functional by creating a state when needed and having no required props
|
| 40 |
-
- Make sure to include all necessary code in one file
|
| 41 |
-
- There are no additional files in the local file system, unless you create them inside the same program
|
| 42 |
-
- Do not touch project dependencies files like package.json, package-lock.json, requirements.txt, etc
|
| 43 |
|
| 44 |
When developing with React or Vue components, follow these specific requirements:
|
| 45 |
- Use TypeScript or JavaScript as the language
|
|
@@ -54,6 +44,8 @@ When developing with React or Vue components, follow these specific requirements
|
|
| 54 |
|
| 55 |
For Python development, you must follow these constraints:
|
| 56 |
- For any programs that require user inputs, you MUST USE `gradio` or `streamlit`
|
|
|
|
|
|
|
| 57 |
- Choose suitable PyPI packages to be imported, e.g., `import pandas`
|
| 58 |
- Avoid using libraries that require desktop GUI interfaces, with the exceptions of `pygame`, `gradio`, and `streamlit` which are explicitly supported
|
| 59 |
- For PyGame applications, we use pygbag to build the application. You have to write the main function as an async function like:
|
|
@@ -115,7 +107,7 @@ FOR NPM INSTALLATIONS:
|
|
| 115 |
FOR PIP INSTALLATIONS:
|
| 116 |
- YOU MUST NOT INSTALL ANY DEEP LEARNING DEPENDENCIES. THE ENVIRONMENT IS CPU ONLY.
|
| 117 |
- IF THE USER SAYS TO INSTALL A PACKAGE, YOU MUST INSTALL IT.
|
| 118 |
-
- Use `uv pip install
|
| 119 |
|
| 120 |
YOU DONT NEED TO INSTALL ANY FOLLOWING DEPENDENCIES:
|
| 121 |
- `gradio`, `streamlit`, `pygame`, `mermaid`, `react`, `react-dom`, `vue`
|
|
|
|
| 28 |
```
|
| 29 |
|
| 30 |
Before you begin writing any code, you must follow these fundamental rules:
|
|
|
|
|
|
|
| 31 |
- ALWAYS generate complete, self-contained code in a single file
|
| 32 |
- You CAN NOT split your program into multiple files or multiple code blocks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
When developing with React or Vue components, follow these specific requirements:
|
| 35 |
- Use TypeScript or JavaScript as the language
|
|
|
|
| 44 |
|
| 45 |
For Python development, you must follow these constraints:
|
| 46 |
- For any programs that require user inputs, you MUST USE `gradio` or `streamlit`
|
| 47 |
+
- Gradio Apps MUST start at port 7860
|
| 48 |
+
- Streamlit Apps MUST start at port 8501
|
| 49 |
- Choose suitable PyPI packages to be imported, e.g., `import pandas`
|
| 50 |
- Avoid using libraries that require desktop GUI interfaces, with the exceptions of `pygame`, `gradio`, and `streamlit` which are explicitly supported
|
| 51 |
- For PyGame applications, we use pygbag to build the application. You have to write the main function as an async function like:
|
|
|
|
| 107 |
FOR PIP INSTALLATIONS:
|
| 108 |
- YOU MUST NOT INSTALL ANY DEEP LEARNING DEPENDENCIES. THE ENVIRONMENT IS CPU ONLY.
|
| 109 |
- IF THE USER SAYS TO INSTALL A PACKAGE, YOU MUST INSTALL IT.
|
| 110 |
+
- Use `uv pip install` to install packages.
|
| 111 |
|
| 112 |
YOU DONT NEED TO INSTALL ANY FOLLOWING DEPENDENCIES:
|
| 113 |
- `gradio`, `streamlit`, `pygame`, `mermaid`, `react`, `react-dom`, `vue`
|
sandbox/sandbox_manager.py
CHANGED
|
@@ -75,6 +75,8 @@ def run_command_in_sandbox(
|
|
| 75 |
stderrs: list[str] = []
|
| 76 |
|
| 77 |
try:
|
|
|
|
|
|
|
| 78 |
command_result = sandbox.commands.run(
|
| 79 |
cmd=command,
|
| 80 |
cwd=working_directory,
|
|
|
|
| 75 |
stderrs: list[str] = []
|
| 76 |
|
| 77 |
try:
|
| 78 |
+
if "uv" in command:
|
| 79 |
+
command = "uv venv;" + command
|
| 80 |
command_result = sandbox.commands.run(
|
| 81 |
cmd=command,
|
| 82 |
cwd=working_directory,
|
sandbox/sandbox_telemetry.py
CHANGED
|
@@ -205,8 +205,8 @@ def log_sandbox_telemetry_gradio_fn(
|
|
| 205 |
default=str,
|
| 206 |
ensure_ascii=False
|
| 207 |
)
|
| 208 |
-
filename = get_sandbox_log_filename(sandbox_state)
|
| 209 |
-
upsert_sandbox_log(filename=filename, data=log_data)
|
| 210 |
|
| 211 |
# # Upload to Azure Blob Storage
|
| 212 |
# if AZURE_BLOB_STORAGE_CONNECTION_STRING:
|
|
|
|
| 205 |
default=str,
|
| 206 |
ensure_ascii=False
|
| 207 |
)
|
| 208 |
+
# filename = get_sandbox_log_filename(sandbox_state)
|
| 209 |
+
# upsert_sandbox_log(filename=filename, data=log_data)
|
| 210 |
|
| 211 |
# # Upload to Azure Blob Storage
|
| 212 |
# if AZURE_BLOB_STORAGE_CONNECTION_STRING:
|