Spaces:
Runtime error
Runtime error
Update src/app.py
Browse files- src/app.py +19 -9
src/app.py
CHANGED
|
@@ -1,18 +1,28 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
app_code = os.environ.get("APP_CODE", "")
|
|
|
|
| 5 |
|
| 6 |
-
def execute_code(code_str):
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
except Exception as e:
|
| 13 |
-
st.error(f"Error
|
| 14 |
|
|
|
|
| 15 |
if app_code:
|
| 16 |
execute_code(app_code)
|
| 17 |
else:
|
| 18 |
-
st.error("
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import types
|
| 4 |
|
| 5 |
+
# Retrieve your hidden code from the environment variable
|
| 6 |
app_code = os.environ.get("APP_CODE", "")
|
| 7 |
+
st.write(app_code)
|
| 8 |
|
| 9 |
+
def execute_code(code_str: str):
|
| 10 |
+
"""
|
| 11 |
+
Dynamically compile and execute the provided code string.
|
| 12 |
+
If it defines a `main()` function, call it.
|
| 13 |
+
"""
|
| 14 |
try:
|
| 15 |
+
# Create a fresh module namespace
|
| 16 |
+
dynamic_module = types.ModuleType("dynamic_app")
|
| 17 |
+
exec(code_str, dynamic_module.__dict__)
|
| 18 |
+
# If the app defines a main(), invoke it
|
| 19 |
+
if hasattr(dynamic_module, "main"):
|
| 20 |
+
dynamic_module.main()
|
| 21 |
except Exception as e:
|
| 22 |
+
st.error(f"Error while executing hidden code: {e}")
|
| 23 |
|
| 24 |
+
# Load and run, or show an error
|
| 25 |
if app_code:
|
| 26 |
execute_code(app_code)
|
| 27 |
else:
|
| 28 |
+
st.error("Cannot load the app code. Did you set the APP_CODE secret correctly?")
|