Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
try:
|
| 6 |
+
# Get the code from secrets
|
| 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()
|