gskdsrikrishna commited on
Commit
d503c6c
·
verified ·
1 Parent(s): 4a516ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+
5
+ # Load API key from Hugging Face secrets
6
+ api_key = os.getenv("KEY")
7
+
8
+ # Streamlit UI
9
+ st.title("Python Code Compiler")
10
+ st.write("Compile and run Python code using an online compiler API.")
11
+
12
+ code_input = st.text_area("Enter your Python code:", "print('Hello, World!')")
13
+
14
+ def 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
+
24
+ if st.button("Run Code"):
25
+ with st.spinner("Compiling..."):
26
+ result = compile_code(code_input)
27
+
28
+ if "output" in result:
29
+ st.success("Execution Output:")
30
+ st.code(result["output"], language="python")
31
+ else:
32
+ st.error("Failed to compile code.")
33
+ st.write("Response Data:", result) # Debugging: Show response data