MLDeveloper commited on
Commit
34602ec
Β·
verified Β·
1 Parent(s): b61fe25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -58
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", json={"code": code})
49
- output = response.json().get("output", "Error in execution.")
50
-
51
- # Display output
52
- st.subheader("πŸ“Œ Output:")
53
- st.code(output, language="text")
54
-
55
- except requests.exceptions.RequestException as e:
56
- st.error(f"⚠️ Error connecting to the backend: {e}")
57
- else:
58
- st.warning("⚠️ Please write some Python code before running.")
 
 
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.")