Spaces:
Sleeping
Sleeping
Commit Β·
a96851e
1
Parent(s): 26ee0de
Auto-commit: app.py updated
Browse files114 unmodified lines115116117118119120121122123124125126127128129114 unmodified linesif result.stderr:output += f"\n--- STDERR ---\n{result.stderr}"# For React/JS with output, create previewpreview = Noneif language.lower() in ["react", "javascript"] and "<" in code:preview = base64.b64encode(code.encode()).decode()return {"output": output or "Execution completed successfully","exit_code": result.returncode,"preview": preview,"security": "π Landrun kernel-level isolation active"}114 unmodified lines115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189114 unmodified linesif result.stderr:output += f"\n--- STDERR ---\n{result.stderr}"# Generate preview HTML and store with unique IDpreview_id = str(uuid.uuid4())preview_url = Nonepreview_html = None# React: Always create preview with JSXif language.lower() == "react":preview_html = f"""<!DOCTYPE html><html><head><meta charset="UTF-8"><script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script><script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script><script src="https://unpkg.com/@babel/standalone/babel.min.js"></script><style>body {{ font-family: Arial, sans-serif; padding: 20px; }}</style></head><body><div id="root"></div><script type="text/babel">{code}const root = ReactDOM.createRoot(document.getElementById('root'));root.render(<App />);</script></body></html>"""# JavaScript: If code contains HTML-like output, render itelif language.lower() == "javascript" and any(tag in code.lower() for tag in ["<div", "<p>", "<h1", "<span", "document."]):preview_html = f"""<!DOCTYPE html><html><head><meta charset="UTF-8"><style>body {{ font-family: Arial, sans-serif; padding: 20px; }}</style></head><body><div id="output"></div><script>{code}</script></body></html>"""# HTML: Direct renderingelif language.lower() == "html":preview_html = code# Python: Create visual output if matplotlib/plotting detectedelif language.lower() == "python":if "<html" in output.lower() or "<!doctype" in output.lower():preview_html = outputelif any(lib in code.lower() for lib in ["matplotlib", "plotly", "seaborn"]):output += "\n[π‘ Tip: Save plots to HTML for preview]"# Store preview and generate URLif preview_html:PREVIEW_STORAGE[preview_id] = {"html": preview_html,"created": datetime.now(),"language": language}# Generate public preview URLpreview_url = f"/preview/{preview_id}"preview_base64 = base64.b64encode(preview_html.encode()).decode()else:preview_base64 = Nonereturn {"output": output or "Execution completed successfully","exit_code": result.returncode,"preview": preview_base64,"preview_url": preview_url, # NEW: AI agents can GET this URL"security": "π Landrun kernel-level isolation active"}
app.py+65-5