CoolFace
Apppublic

gskdsrikrishna/Python_Compiler

sourceHugging Faceotherupdated 2y agoView on Hugging Face
0likes
app.py36 linesDownload Raw Back to root
1import streamlit as st2import requests3import os4 5# Load API key from Hugging Face secrets6api_key = os.getenv("KEY")7 8# Streamlit UI9st.title("Python Code Compiler")10st.write("Compile and run Python code using an online compiler API.")11 12code_input = st.text_area("Enter your Python code:", "print('Hello, World!')")13 14def compile_code(code):15    url = "https://python-code-compiler.p.rapidapi.com/compile"16    headers = {17        "x-rapidapi-key": api_key,18        "x-rapidapi-host": "python-code-compiler.p.rapidapi.com",19        "Content-Type": "text/plain"20    }21    response = requests.post(url, data=code, headers=headers)22    return response.json()23 24if st.button("Run Code"):25    with st.spinner("Compiling..."):26        result = compile_code(code_input)27        28        stdout_output = result.get("stdout", "")29        30        if stdout_output:31            st.success("Execution Output:")32            st.code(stdout_output, language="python")33        else:34            st.error("Failed to compile code.")35            st.write("Response Data:", result)  # Debugging: Show response data36