Spaces:
Running
Running
File size: 1,044 Bytes
d503c6c |
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 |
import streamlit as st
import requests
import os
# Load API key from Hugging Face secrets
api_key = os.getenv("KEY")
# Streamlit UI
st.title("Python Code Compiler")
st.write("Compile and run Python code using an online compiler API.")
code_input = st.text_area("Enter your Python code:", "print('Hello, World!')")
def compile_code(code):
url = "https://python-code-compiler.p.rapidapi.com/compile"
headers = {
"x-rapidapi-key": api_key,
"x-rapidapi-host": "python-code-compiler.p.rapidapi.com",
"Content-Type": "text/plain"
}
response = requests.post(url, data=code, headers=headers)
return response.json()
if st.button("Run Code"):
with st.spinner("Compiling..."):
result = compile_code(code_input)
if "output" in result:
st.success("Execution Output:")
st.code(result["output"], language="python")
else:
st.error("Failed to compile code.")
st.write("Response Data:", result) # Debugging: Show response data
|