|
import os |
|
import sys |
|
import streamlit as st |
|
from tempfile import NamedTemporaryFile |
|
|
|
def main(): |
|
try: |
|
|
|
code = os.environ.get("MAIN_CODE") |
|
|
|
if not code: |
|
st.error("⚠️ The application code wasn't found in secrets. Please add the MAIN_CODE secret.") |
|
return |
|
|
|
|
|
try: |
|
|
|
compile(code, '<string>', 'exec') |
|
except SyntaxError as e: |
|
st.error(f"⚠️ Syntax error in the application code: {str(e)}") |
|
st.info("Please check your code for unterminated strings or other syntax errors.") |
|
|
|
|
|
if hasattr(e, 'lineno') and hasattr(e, 'text'): |
|
st.code(f"Line {e.lineno}: {e.text}") |
|
st.write(f"Error occurs near character position: {e.offset}") |
|
return |
|
|
|
|
|
with NamedTemporaryFile(suffix='.py', delete=False, mode='w') as tmp: |
|
tmp.write(code) |
|
tmp_path = tmp.name |
|
|
|
|
|
exec(compile(code, tmp_path, 'exec'), globals()) |
|
|
|
|
|
try: |
|
os.unlink(tmp_path) |
|
except: |
|
pass |
|
|
|
except Exception as e: |
|
st.error(f"⚠️ Error loading or executing the application: {str(e)}") |
|
import traceback |
|
st.code(traceback.format_exc()) |
|
|
|
if __name__ == "__main__": |
|
main() |