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