Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,59 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
-
from streamlit_ace import st_ace
|
| 4 |
-
|
| 5 |
-
# Configure Streamlit page
|
| 6 |
-
st.set_page_config(
|
| 7 |
-
page_title="Online Python Compiler",
|
| 8 |
-
page_icon="🐍",
|
| 9 |
-
layout="wide"
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
st.title("🐍 Online Python Compiler")
|
| 13 |
-
|
| 14 |
-
# Custom CSS for better design
|
| 15 |
-
st.markdown(
|
| 16 |
-
"""
|
| 17 |
-
<style>
|
| 18 |
-
body { background-color: #E3F2FD; }
|
| 19 |
-
.stTextArea textarea { font-size: 16px; font-family: monospace; }
|
| 20 |
-
.stButton button { background-color: #1E90FF; color: white; }
|
| 21 |
-
</style>
|
| 22 |
-
""",
|
| 23 |
-
unsafe_allow_html=True,
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
# Default Python code template
|
| 27 |
-
default_code = '''# Write your Python code here
|
| 28 |
-
print("Hello, World!")
|
| 29 |
-
'''
|
| 30 |
-
|
| 31 |
-
# Code editor (using Ace Editor)
|
| 32 |
-
code = st_ace(
|
| 33 |
-
value=default_code,
|
| 34 |
-
language="python",
|
| 35 |
-
theme="monokai",
|
| 36 |
-
key="python_editor",
|
| 37 |
-
font_size=16,
|
| 38 |
-
height=300,
|
| 39 |
-
auto_update=True,
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
# Run button
|
| 43 |
-
if st.button("▶ Run Code"):
|
| 44 |
-
if code.strip():
|
| 45 |
-
with st.spinner("Running your code..."):
|
| 46 |
-
try:
|
| 47 |
-
# Send code to backend
|
| 48 |
-
response = requests.post("http://127.0.0.1:5000/run"
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
st.
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from streamlit_ace import st_ace
|
| 4 |
+
|
| 5 |
+
# Configure Streamlit page
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="Online Python Compiler",
|
| 8 |
+
page_icon="🐍",
|
| 9 |
+
layout="wide"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
st.title("🐍 Online Python Compiler")
|
| 13 |
+
|
| 14 |
+
# Custom CSS for better design
|
| 15 |
+
st.markdown(
|
| 16 |
+
"""
|
| 17 |
+
<style>
|
| 18 |
+
body { background-color: #E3F2FD; }
|
| 19 |
+
.stTextArea textarea { font-size: 16px; font-family: monospace; }
|
| 20 |
+
.stButton button { background-color: #1E90FF; color: white; }
|
| 21 |
+
</style>
|
| 22 |
+
""",
|
| 23 |
+
unsafe_allow_html=True,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Default Python code template
|
| 27 |
+
default_code = '''# Write your Python code here
|
| 28 |
+
print("Hello, World!")
|
| 29 |
+
'''
|
| 30 |
+
|
| 31 |
+
# Code editor (using Ace Editor)
|
| 32 |
+
code = st_ace(
|
| 33 |
+
value=default_code,
|
| 34 |
+
language="python",
|
| 35 |
+
theme="monokai",
|
| 36 |
+
key="python_editor",
|
| 37 |
+
font_size=16,
|
| 38 |
+
height=300,
|
| 39 |
+
auto_update=True,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# Run button
|
| 43 |
+
if st.button("▶ Run Code"):
|
| 44 |
+
if code.strip():
|
| 45 |
+
with st.spinner("Running your code..."):
|
| 46 |
+
try:
|
| 47 |
+
# Send code to backend
|
| 48 |
+
response = requests.post("API_URL = "http://127.0.0.1:5000/run"
|
| 49 |
+
", json={"code": code})
|
| 50 |
+
output = response.json().get("output", "Error in execution.")
|
| 51 |
+
|
| 52 |
+
# Display output
|
| 53 |
+
st.subheader("📌 Output:")
|
| 54 |
+
st.code(output, language="text")
|
| 55 |
+
|
| 56 |
+
except requests.exceptions.RequestException as e:
|
| 57 |
+
st.error(f"⚠️ Error connecting to the backend: {e}")
|
| 58 |
+
else:
|
| 59 |
+
st.warning("⚠️ Please write some Python code before running.")
|