Spaces:
Running
Running
Update tests.py
Browse files
tests.py
CHANGED
@@ -208,12 +208,23 @@ def create_code_files(filename: str, code: str) -> dict:
|
|
208 |
f.write(code)
|
209 |
f.close()
|
210 |
return {"info":"task completed. The referenced code files were created successfully. "}
|
211 |
-
|
212 |
@mcp.tool()
|
213 |
def run_code(python_packages:str,filename: str, code: str,start_cmd:str) -> dict:
|
214 |
-
"""
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
"""
|
218 |
|
219 |
global files_list
|
@@ -236,7 +247,6 @@ def run_code(python_packages:str,filename: str, code: str,start_cmd:str) -> dict
|
|
236 |
run(start_cmd, 300)
|
237 |
while stderr=="" and stdout=="":
|
238 |
pass
|
239 |
-
time.sleep(1.5)
|
240 |
onlyfiles = glob.glob("/app/code_interpreter/*")
|
241 |
onlyfiles=list(set(onlyfiles)-set(files_list))
|
242 |
uploaded_filenames=[]
|
|
|
208 |
f.write(code)
|
209 |
f.close()
|
210 |
return {"info":"task completed. The referenced code files were created successfully. "}
|
211 |
+
|
212 |
@mcp.tool()
|
213 |
def run_code(python_packages:str,filename: str, code: str,start_cmd:str) -> dict:
|
214 |
+
"""
|
215 |
+
Execute Python code in a controlled environment with package installation and file handling.
|
216 |
+
|
217 |
+
Args:
|
218 |
+
python_packages: Space-separated list of packages to install (e.g., "numpy matplotlib").
|
219 |
+
Preinstalled packages: gradio, XlsxWriter, openpyxl.
|
220 |
+
filename: Name of the file to create (stored in /app/code_interpreter/).
|
221 |
+
code: Full Python code to write to the file.
|
222 |
+
start_cmd: Command to execute the file (e.g., "python /app/code_interpreter/app.py"
|
223 |
+
or "bash /app/code_interpreter/app.py").
|
224 |
+
|
225 |
+
Notes:
|
226 |
+
- All user-uploaded files are in /app/code_interpreter/.
|
227 |
+
- After execution, embed a download link (or display images/gifs/videos directly in markdown format) in your response.
|
228 |
"""
|
229 |
|
230 |
global files_list
|
|
|
247 |
run(start_cmd, 300)
|
248 |
while stderr=="" and stdout=="":
|
249 |
pass
|
|
|
250 |
onlyfiles = glob.glob("/app/code_interpreter/*")
|
251 |
onlyfiles=list(set(onlyfiles)-set(files_list))
|
252 |
uploaded_filenames=[]
|