Spaces:
Running
Running
Update tests.py
Browse files
tests.py
CHANGED
@@ -200,15 +200,54 @@ def analyse_images(imagepath,query) -> dict:
|
|
200 |
|
201 |
@mcp.tool()
|
202 |
def create_code_files(filename: str, code: str) -> dict:
|
|
|
203 |
global destination_dir
|
204 |
download_all_files("https://opengpt-4ik5.onrender.com", "/upload", "/app/code_interpreter")
|
205 |
-
"""Create code files by passing the the filename as well the entire code to write.The file is created by default in the /app/code_interpreter directory.Note:All user uploaded files that you might need to work upon are stored in the /app/code_interpreter directory."""
|
206 |
transfer_files()
|
207 |
f = open(os.path.join(destination_dir, filename), "w")
|
208 |
f.write(code)
|
209 |
f.close()
|
210 |
return {"info":"task completed. The referenced code files were created successfully. "}
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
|
214 |
@mcp.tool()
|
@@ -388,4 +427,3 @@ if __name__ == "__main__":
|
|
388 |
# info={"info":f"Your Application is live [here](https://{url})"}
|
389 |
|
390 |
# return info
|
391 |
-
|
|
|
200 |
|
201 |
@mcp.tool()
|
202 |
def create_code_files(filename: str, code: str) -> dict:
|
203 |
+
"""Create code files by passing the the filename as well the entire code to write.The file is created by default in the /app/code_interpreter directory.Note:All user uploaded files that you might need to work upon are stored in the /app/code_interpreter directory."""
|
204 |
global destination_dir
|
205 |
download_all_files("https://opengpt-4ik5.onrender.com", "/upload", "/app/code_interpreter")
|
|
|
206 |
transfer_files()
|
207 |
f = open(os.path.join(destination_dir, filename), "w")
|
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 |
+
"""python_packages:python_packages to install seperated by space.eg-(python packages:numpy matplotlib).The following python packages are preinstalled:gradio XlsxWriter openpyxl
|
215 |
+
filename,code:Create code files by passing the the filename as well the entire code to write.The file is created by default in the /app/code_interpreter directory.Note:All user uploaded files that you might need to work upon are stored in the /app/code_interpreter directory.
|
216 |
+
start_cmd:Example- python /app/code_interpreter/app.py or bash /app/code_interpreter/app.py.The files must be inside the /app/code_interpreter directory.
|
217 |
+
"""
|
218 |
+
|
219 |
+
global files_list
|
220 |
+
global stdout
|
221 |
+
global stderr
|
222 |
+
package_names = python_packages.strip()
|
223 |
+
command="pip install"
|
224 |
+
if not package_names:
|
225 |
+
return
|
226 |
+
|
227 |
+
run(
|
228 |
+
f"{command} --break-system-packages {package_names}", timeout_sec=300
|
229 |
+
)
|
230 |
+
global destination_dir
|
231 |
+
download_all_files("https://opengpt-4ik5.onrender.com", "/upload", "/app/code_interpreter")
|
232 |
+
transfer_files()
|
233 |
+
f = open(os.path.join(destination_dir, filename), "w")
|
234 |
+
f.write(code)
|
235 |
+
f.close()
|
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=[]
|
243 |
+
for files in onlyfiles:
|
244 |
+
try:
|
245 |
+
uploaded_filename = upload_file(files, "https://opengpt-4ik5.onrender.com/upload")
|
246 |
+
uploaded_filenames.append(f"https://opengpt-4ik5.onrender.com/static/{uploaded_filename}")
|
247 |
+
except:
|
248 |
+
pass
|
249 |
+
files_list=onlyfiles
|
250 |
+
return {"info":"task completed","stdout":stdout,"stderr":stderr,"Files_download_link":uploaded_filenames}
|
251 |
|
252 |
|
253 |
@mcp.tool()
|
|
|
427 |
# info={"info":f"Your Application is live [here](https://{url})"}
|
428 |
|
429 |
# return info
|
|