Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
-
import streamlit as st
|
| 4 |
-
from tempfile import NamedTemporaryFile
|
| 5 |
|
| 6 |
def main():
|
| 7 |
try:
|
|
@@ -9,27 +7,27 @@ def main():
|
|
| 9 |
code = os.environ.get("MAIN_CODE")
|
| 10 |
|
| 11 |
if not code:
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
tmp.write(code)
|
| 18 |
-
tmp_path = tmp.name
|
| 19 |
|
| 20 |
-
# Execute the code
|
| 21 |
-
exec(compile(code, tmp_path, 'exec'), globals())
|
| 22 |
-
|
| 23 |
-
# Clean up the temporary file
|
| 24 |
-
try:
|
| 25 |
-
os.unlink(tmp_path)
|
| 26 |
-
except:
|
| 27 |
-
pass
|
| 28 |
-
|
| 29 |
except Exception as e:
|
| 30 |
-
|
| 31 |
import traceback
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
main()
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def main():
|
| 5 |
try:
|
|
|
|
| 7 |
code = os.environ.get("MAIN_CODE")
|
| 8 |
|
| 9 |
if not code:
|
| 10 |
+
# Fallback: create a simple error display
|
| 11 |
+
import gradio as gr
|
| 12 |
+
with gr.Blocks() as demo:
|
| 13 |
+
gr.Markdown("# ⚠️ Error")
|
| 14 |
+
gr.Markdown("The application code wasn't found in secrets. Please add the MAIN_CODE secret.")
|
| 15 |
+
demo.launch()
|
| 16 |
return
|
| 17 |
|
| 18 |
+
# Execute the code directly
|
| 19 |
+
exec(compile(code, '<string>', 'exec'), globals())
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
except Exception as e:
|
| 22 |
+
import gradio as gr
|
| 23 |
import traceback
|
| 24 |
+
error_msg = traceback.format_exc()
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("# ⚠️ Error Loading Application")
|
| 28 |
+
gr.Markdown(f"**Error:** {str(e)}")
|
| 29 |
+
gr.Code(error_msg, language="python", label="Traceback")
|
| 30 |
+
demo.launch()
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
main()
|