Harshith Reddy
commited on
Commit
Β·
963eb0b
1
Parent(s):
1204e53
CRITICAL FIX: Create app directly at module level - no functions, no conditionals, no delays
Browse files
app.py
CHANGED
|
@@ -966,86 +966,18 @@ def create_interface():
|
|
| 966 |
|
| 967 |
return demo
|
| 968 |
|
| 969 |
-
|
|
|
|
| 970 |
|
| 971 |
-
root = FastAPI(title="SRMA-Mamba
|
| 972 |
root.mount("/api", api_app)
|
| 973 |
|
|
|
|
|
|
|
| 974 |
@root.get("/healthz")
|
| 975 |
-
def
|
| 976 |
return {"status": "ok"}
|
| 977 |
|
| 978 |
-
app = root
|
| 979 |
-
|
| 980 |
-
print("=" * 60)
|
| 981 |
-
print("Initializing SRMA-Mamba Liver Segmentation Space...")
|
| 982 |
-
print("=" * 60)
|
| 983 |
-
|
| 984 |
-
try:
|
| 985 |
-
demo = create_interface()
|
| 986 |
-
demo.queue()
|
| 987 |
-
print("β Gradio interface created and queued")
|
| 988 |
-
|
| 989 |
-
if not HAS_MOUNT_GRADIO_APP:
|
| 990 |
-
print("β CRITICAL ERROR: mount_gradio_app not available!")
|
| 991 |
-
print("β Gradio version is too old. Need >= 4.44.1")
|
| 992 |
-
print("β Please check requirements.txt has gradio==4.44.1")
|
| 993 |
-
raise ImportError("mount_gradio_app not available. Upgrade Gradio to >= 4.44.1")
|
| 994 |
-
|
| 995 |
-
app = mount_gradio_app(root, demo, path="/")
|
| 996 |
-
print("β Gradio mounted on FastAPI app via mount_gradio_app()")
|
| 997 |
-
print(f"β App type after mount: {type(app)}")
|
| 998 |
-
print(f"β App is root: {app is root}")
|
| 999 |
-
print(f"β App is callable: {callable(app)}")
|
| 1000 |
-
|
| 1001 |
-
print("βΉ Models will be loaded on first inference (lazy loading)")
|
| 1002 |
-
print("=" * 60)
|
| 1003 |
-
print("β Initialization complete")
|
| 1004 |
-
|
| 1005 |
-
except Exception as e:
|
| 1006 |
-
print(f"β Failed to initialize: {e}")
|
| 1007 |
-
import traceback
|
| 1008 |
-
traceback.print_exc()
|
| 1009 |
-
|
| 1010 |
-
try:
|
| 1011 |
-
with gr.Blocks(title="SRMA-Mamba: Error", theme=gr.themes.Soft()) as error_demo:
|
| 1012 |
-
gr.Markdown(f"""
|
| 1013 |
-
# β Error Initializing Interface
|
| 1014 |
-
The application failed to start. Please check the logs for details.
|
| 1015 |
-
|
| 1016 |
-
**Error:** {str(e)}
|
| 1017 |
-
|
| 1018 |
-
**Common causes:**
|
| 1019 |
-
- Missing dependencies
|
| 1020 |
-
- Model files not found
|
| 1021 |
-
- Import errors
|
| 1022 |
-
|
| 1023 |
-
Please check the Space logs for more information.
|
| 1024 |
-
""")
|
| 1025 |
-
error_demo.queue()
|
| 1026 |
-
root = FastAPI(title="SRMA-Mamba Error App")
|
| 1027 |
-
root.mount("/api", api_app)
|
| 1028 |
-
app = mount_gradio_app(root, error_demo, path="/")
|
| 1029 |
-
demo = error_demo
|
| 1030 |
-
print("β Error interface created as fallback")
|
| 1031 |
-
except Exception as e2:
|
| 1032 |
-
print(f"β Even error interface failed: {e2}")
|
| 1033 |
-
import traceback
|
| 1034 |
-
traceback.print_exc()
|
| 1035 |
-
with gr.Blocks() as final_fallback:
|
| 1036 |
-
gr.Markdown("# Critical Error - Check logs")
|
| 1037 |
-
app = final_fallback
|
| 1038 |
-
demo = final_fallback
|
| 1039 |
-
|
| 1040 |
-
if app is None:
|
| 1041 |
-
print("β CRITICAL: app is None after initialization!")
|
| 1042 |
-
raise RuntimeError("App was not set during initialization")
|
| 1043 |
-
|
| 1044 |
-
print(f"β Final app variable set: {app is not None}")
|
| 1045 |
-
print(f"β App type at module level: {type(app)}")
|
| 1046 |
-
print(f"β App has __call__: {hasattr(app, '__call__')}")
|
| 1047 |
-
|
| 1048 |
if __name__ == "__main__":
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 966 |
|
| 967 |
return demo
|
| 968 |
|
| 969 |
+
demo = create_interface()
|
| 970 |
+
demo.queue()
|
| 971 |
|
| 972 |
+
root = FastAPI(title="SRMA-Mamba")
|
| 973 |
root.mount("/api", api_app)
|
| 974 |
|
| 975 |
+
app = mount_gradio_app(root, demo, path="/")
|
| 976 |
+
|
| 977 |
@root.get("/healthz")
|
| 978 |
+
def healthz():
|
| 979 |
return {"status": "ok"}
|
| 980 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 981 |
if __name__ == "__main__":
|
| 982 |
+
import uvicorn
|
| 983 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|