import streamlit as st import requests from streamlit_ace import st_ace # Configure Streamlit page st.set_page_config( page_title="Online Python Compiler", page_icon="🐍", layout="wide" ) # Custom CSS for background, text, and tabs tabs_css = """ """ st.markdown(tabs_css, unsafe_allow_html=True) st.title("🐍 Online Python Compiler") # Default Python code template default_code = '''# Write your Python code here print("Hello, World!") ''' # Code editor (using Ace Editor) code = st_ace( value=default_code, language="python", theme="monokai", key="python_editor", font_size=16, height=300, auto_update=True, ) # Run button if st.button("▶ Run Code"): if code.strip(): with st.spinner("Running your code..."): try: # Send code to backend API_URL = "https://your-backend-service.onrender.com/run" # Replace with actual backend URL response = requests.post(API_URL, json={"code": code}) # Make API call # Get output output = response.json().get("output", "Error in execution.") # Display output st.subheader("📌 Output:") st.code(output, language="text") except requests.exceptions.RequestException as e: st.error(f"⚠️ Error connecting to the backend: {e}") else: st.warning("⚠️ Please write some Python code before running.")