|
import streamlit as st |
|
import os |
|
import types |
|
|
|
|
|
app_code = os.environ.get("APP_CODE", "") |
|
|
|
def execute_code(code_str: str): |
|
""" |
|
Dynamically compile and execute the provided code string. |
|
If it defines a `main()` function, call it. |
|
""" |
|
try: |
|
|
|
dynamic_module = types.ModuleType("dynamic_app") |
|
exec(code_str, dynamic_module.__dict__) |
|
|
|
if hasattr(dynamic_module, "main"): |
|
dynamic_module.main() |
|
except Exception as e: |
|
st.error(f"Error while executing hidden code: {e}") |
|
|
|
|
|
if app_code: |
|
execute_code(app_code) |
|
else: |
|
st.error("Cannot load the app code. Did you set the APP_CODE secret correctly?") |
|
|