Spaces:
Running
Running
fixes
Browse files- app.py +14 -3
- jupyter_handler.py +3 -3
app.py
CHANGED
@@ -30,6 +30,7 @@ SANDBOXES = {}
|
|
30 |
SANDBOX_TIMEOUT = 300
|
31 |
TMP_DIR = './tmp/'
|
32 |
model="Qwen/Qwen3-Coder-480B-A35B-Instruct:cerebras"
|
|
|
33 |
|
34 |
if not os.path.exists(TMP_DIR):
|
35 |
os.makedirs(TMP_DIR)
|
@@ -48,6 +49,7 @@ The following files are available (if any):
|
|
48 |
def execute_jupyter_agent(
|
49 |
user_input, files, message_history, request: gr.Request
|
50 |
):
|
|
|
51 |
if request.session_hash not in SANDBOXES:
|
52 |
SANDBOXES[request.session_hash] = Sandbox(api_key=E2B_API_KEY, timeout=SANDBOX_TIMEOUT)
|
53 |
sbx = SANDBOXES[request.session_hash]
|
@@ -56,6 +58,10 @@ def execute_jupyter_agent(
|
|
56 |
os.makedirs(save_dir, exist_ok=True)
|
57 |
save_dir = os.path.join(save_dir, 'jupyter-agent.ipynb')
|
58 |
|
|
|
|
|
|
|
|
|
59 |
client = OpenAI(
|
60 |
base_url="https://router.huggingface.co/v1",
|
61 |
api_key=HF_TOKEN,
|
@@ -99,9 +105,13 @@ def execute_jupyter_agent(
|
|
99 |
json.dump(notebook_data, f, indent=2)
|
100 |
yield notebook_html, message_history, save_dir
|
101 |
|
102 |
-
def clear(msg_state):
|
|
|
|
|
|
|
|
|
103 |
msg_state = []
|
104 |
-
return
|
105 |
|
106 |
|
107 |
css = """
|
@@ -142,7 +152,7 @@ with gr.Blocks() as demo:
|
|
142 |
|
143 |
powered_html = gr.HTML("""\
|
144 |
<p align="center">
|
145 |
-
|
146 |
</p>""")
|
147 |
|
148 |
|
@@ -150,6 +160,7 @@ with gr.Blocks() as demo:
|
|
150 |
fn=execute_jupyter_agent,
|
151 |
inputs=[user_input, files, msg_state],
|
152 |
outputs=[html_output, msg_state, file],
|
|
|
153 |
)
|
154 |
|
155 |
clear_btn.click(fn=clear, inputs=[msg_state], outputs=[html_output, msg_state])
|
|
|
30 |
SANDBOX_TIMEOUT = 300
|
31 |
TMP_DIR = './tmp/'
|
32 |
model="Qwen/Qwen3-Coder-480B-A35B-Instruct:cerebras"
|
33 |
+
init_notebook = JupyterNotebook()
|
34 |
|
35 |
if not os.path.exists(TMP_DIR):
|
36 |
os.makedirs(TMP_DIR)
|
|
|
49 |
def execute_jupyter_agent(
|
50 |
user_input, files, message_history, request: gr.Request
|
51 |
):
|
52 |
+
|
53 |
if request.session_hash not in SANDBOXES:
|
54 |
SANDBOXES[request.session_hash] = Sandbox(api_key=E2B_API_KEY, timeout=SANDBOX_TIMEOUT)
|
55 |
sbx = SANDBOXES[request.session_hash]
|
|
|
58 |
os.makedirs(save_dir, exist_ok=True)
|
59 |
save_dir = os.path.join(save_dir, 'jupyter-agent.ipynb')
|
60 |
|
61 |
+
with open(save_dir, 'w', encoding='utf-8') as f:
|
62 |
+
json.dump(init_notebook.data, f, indent=2)
|
63 |
+
yield init_notebook.render(), message_history, save_dir
|
64 |
+
|
65 |
client = OpenAI(
|
66 |
base_url="https://router.huggingface.co/v1",
|
67 |
api_key=HF_TOKEN,
|
|
|
105 |
json.dump(notebook_data, f, indent=2)
|
106 |
yield notebook_html, message_history, save_dir
|
107 |
|
108 |
+
def clear(msg_state, request: gr.Request):
|
109 |
+
if request.session_hash in SANDBOXES:
|
110 |
+
SANDBOXES[request.session_hash].kill()
|
111 |
+
SANDBOXES.pop(request.session_hash)
|
112 |
+
|
113 |
msg_state = []
|
114 |
+
return init_notebook.render(), msg_state
|
115 |
|
116 |
|
117 |
css = """
|
|
|
152 |
|
153 |
powered_html = gr.HTML("""\
|
154 |
<p align="center">
|
155 |
+
<img style="max-height:100px; max-width:100%; height:auto;"src="https://huggingface.co/spaces/lvwerra/jupyter-agent-2/resolve/main/powered-by.png" alt="Powered by" />
|
156 |
</p>""")
|
157 |
|
158 |
|
|
|
160 |
fn=execute_jupyter_agent,
|
161 |
inputs=[user_input, files, msg_state],
|
162 |
outputs=[html_output, msg_state, file],
|
163 |
+
show_progress="hidden",
|
164 |
)
|
165 |
|
166 |
clear_btn.click(fn=clear, inputs=[msg_state], outputs=[html_output, msg_state])
|
jupyter_handler.py
CHANGED
@@ -56,10 +56,10 @@ assistant_final_answer_template = """<div class="alert alert-block alert-warning
|
|
56 |
"""
|
57 |
|
58 |
header_message = """<p align="center">
|
59 |
-
<img style="height:120px;
|
|
|
|
|
60 |
</p>
|
61 |
-
|
62 |
-
|
63 |
<p style="text-align:center;">Running Qwen3-Coder-480B-A35B-Instruct in a Jupyter notebook powered by E2B, Cerebras and Hugging Face Inference Providers.</p>"""
|
64 |
|
65 |
bad_html_bad = """input[type="file"] {
|
|
|
56 |
"""
|
57 |
|
58 |
header_message = """<p align="center">
|
59 |
+
<img style="max-height:120px; max-width:100%; height:auto;"
|
60 |
+
src="https://huggingface.co/spaces/lvwerra/jupyter-agent-2/resolve/main/jupyter-agent-2.png"
|
61 |
+
alt="Jupyter Agent Logo" />
|
62 |
</p>
|
|
|
|
|
63 |
<p style="text-align:center;">Running Qwen3-Coder-480B-A35B-Instruct in a Jupyter notebook powered by E2B, Cerebras and Hugging Face Inference Providers.</p>"""
|
64 |
|
65 |
bad_html_bad = """input[type="file"] {
|