File size: 1,566 Bytes
34602ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0363700
34602ec
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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"
)

st.title("๐Ÿ Online Python Compiler")

# Custom CSS for better design
st.markdown(
    """
    <style>
    body { background-color: #E3F2FD; }
    .stTextArea textarea { font-size: 16px; font-family: monospace; }
    .stButton button { background-color: #1E90FF; color: white; }
    </style>
    """,
    unsafe_allow_html=True,
)

# 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
                response = requests.post("API_URL = "https://your-backend-service.onrender.com/run""
", json={"code": code})
                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.")