Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import subprocess
|
| 4 |
import sys
|
| 5 |
import io
|
| 6 |
import os
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
# Function to execute Python code
|
| 9 |
def execute_python(code, user_input):
|
| 10 |
old_stdout = sys.stdout
|
|
@@ -42,7 +45,7 @@ def execute_java(code, user_input):
|
|
| 42 |
if compile_process.returncode != 0:
|
| 43 |
return f"Compilation Error:\n{compile_process.stderr}"
|
| 44 |
|
| 45 |
-
run_process = subprocess.run(["java", "Main"], input=user_input, capture_output=True, text=True)
|
| 46 |
return run_process.stdout if run_process.returncode == 0 else f"Runtime Error:\n{run_process.stderr}"
|
| 47 |
|
| 48 |
# Function to execute C++ code
|
|
@@ -54,7 +57,7 @@ def execute_cpp(code, user_input):
|
|
| 54 |
if compile_process.returncode != 0:
|
| 55 |
return f"Compilation Error:\n{compile_process.stderr}"
|
| 56 |
|
| 57 |
-
run_process = subprocess.run(["./main"], input=user_input, capture_output=True, text=True)
|
| 58 |
return run_process.stdout if run_process.returncode == 0 else f"Runtime Error:\n{run_process.stderr}"
|
| 59 |
|
| 60 |
# Streamlit UI
|
|
@@ -82,7 +85,6 @@ if st.button("Run Code"):
|
|
| 82 |
else:
|
| 83 |
st.warning("⚠️ Please enter some code before running.")
|
| 84 |
|
| 85 |
-
|
| 86 |
# V1 without gemini api
|
| 87 |
|
| 88 |
# import streamlit as st
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
import subprocess
|
| 4 |
import sys
|
| 5 |
import io
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
# Ensure Java and g++ are installed (for cloud environments)
|
| 9 |
+
os.system("apt update && apt install -y default-jdk g++")
|
| 10 |
+
|
| 11 |
# Function to execute Python code
|
| 12 |
def execute_python(code, user_input):
|
| 13 |
old_stdout = sys.stdout
|
|
|
|
| 45 |
if compile_process.returncode != 0:
|
| 46 |
return f"Compilation Error:\n{compile_process.stderr}"
|
| 47 |
|
| 48 |
+
run_process = subprocess.run(["java", "Main"], cwd=os.getcwd(), input=user_input.encode(), capture_output=True, text=True)
|
| 49 |
return run_process.stdout if run_process.returncode == 0 else f"Runtime Error:\n{run_process.stderr}"
|
| 50 |
|
| 51 |
# Function to execute C++ code
|
|
|
|
| 57 |
if compile_process.returncode != 0:
|
| 58 |
return f"Compilation Error:\n{compile_process.stderr}"
|
| 59 |
|
| 60 |
+
run_process = subprocess.run(["./main"], input=user_input.encode(), capture_output=True, text=True)
|
| 61 |
return run_process.stdout if run_process.returncode == 0 else f"Runtime Error:\n{run_process.stderr}"
|
| 62 |
|
| 63 |
# Streamlit UI
|
|
|
|
| 85 |
else:
|
| 86 |
st.warning("⚠️ Please enter some code before running.")
|
| 87 |
|
|
|
|
| 88 |
# V1 without gemini api
|
| 89 |
|
| 90 |
# import streamlit as st
|