Spaces:
Running
Running
File size: 1,658 Bytes
d8245c1 1acd6e1 d8245c1 7a4c9be d8245c1 0f95c64 d8245c1 0f95c64 d8245c1 0e796e5 3a7668f d8245c1 dd75514 d8245c1 dd75514 d8245c1 3c21712 d8245c1 7a4c9be d8245c1 7a4c9be dc2be38 d8245c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import os
import sys
import streamlit as st
from tempfile import NamedTemporaryFile
def main():
try:
# Get the code from secrets
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 to fix any potential string issues
try:
# Just to verify the code is syntactically valid before writing to file
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.")
# Show the problematic line if possible
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
# Create a temporary Python file
with NamedTemporaryFile(suffix='.py', delete=False, mode='w') as tmp:
tmp.write(code)
tmp_path = tmp.name
# Execute the code
exec(compile(code, tmp_path, 'exec'), globals())
# Clean up the temporary file
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() |