Spaces:
Sleeping
Sleeping
Commit ·
4b5354c
1
Parent(s): a2f5849
Auto-commit: app.py updated
Browse files108 unmodified lines109110111112113114115116117118108 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",108 unmodified lines109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162108 unmodified linesif result.stderr:output += f"\n--- STDERR ---\n{result.stderr}"# AUTO-GENERATE PREVIEW for different languagespreview = None# React: Always create preview with JSXif language.lower() == "react":react_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>"""preview = base64.b64encode(react_html.encode()).decode()# 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."]):js_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>"""preview = base64.b64encode(js_html.encode()).decode()# Python: Create visual output if matplotlib/plotting detectedelif language.lower() == "python":# Check if output contains HTML or if code creates visualizationsif "<html" in output.lower() or "<!doctype" in output.lower():preview = base64.b64encode(output.encode()).decode()elif any(lib in code.lower() for lib in ["matplotlib", "plotly", "seaborn"]):# For plotting libraries, suggest HTML outputoutput += "\n[💡 Tip: Save plots to HTML for preview]"return {"output": output or "Execution completed successfully",
app.py+47-3