Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,28 +2,32 @@ import sys
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
|
|
|
| 5 |
|
| 6 |
# Add src to python path so neural_archaeology module is found
|
| 7 |
-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "src")))
|
| 8 |
|
| 9 |
from backend.main import app as fastapi_app
|
| 10 |
|
| 11 |
-
# Dummy GPU function to satisfy ZeroGPU hardware requirements
|
| 12 |
# Dummy GPU function to satisfy ZeroGPU hardware requirements
|
| 13 |
@spaces.GPU
|
| 14 |
def fake_gpu_function():
|
| 15 |
return "BrainBox Backend API is running! Access the frontend to use it."
|
| 16 |
|
| 17 |
-
#
|
| 18 |
fake_gpu_function()
|
| 19 |
|
| 20 |
# Dummy Gradio app to satisfy Hugging Face Spaces routing requirements
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=fake_gpu_function,
|
| 23 |
inputs=[],
|
| 24 |
-
outputs="text",
|
| 25 |
-
title="BrainBox API Core"
|
| 26 |
)
|
| 27 |
|
| 28 |
-
# Mount FastAPI inside Gradio!
|
| 29 |
-
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
+
import uvicorn # Add this import
|
| 6 |
|
| 7 |
# Add src to python path so neural_archaeology module is found
|
| 8 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "src" )))
|
| 9 |
|
| 10 |
from backend.main import app as fastapi_app
|
| 11 |
|
|
|
|
| 12 |
# Dummy GPU function to satisfy ZeroGPU hardware requirements
|
| 13 |
@spaces.GPU
|
| 14 |
def fake_gpu_function():
|
| 15 |
return "BrainBox Backend API is running! Access the frontend to use it."
|
| 16 |
|
| 17 |
+
# Explicitly invoke the function once during startup to register the ZeroGPU daemon
|
| 18 |
fake_gpu_function()
|
| 19 |
|
| 20 |
# Dummy Gradio app to satisfy Hugging Face Spaces routing requirements
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=fake_gpu_function,
|
| 23 |
inputs=[],
|
| 24 |
+
outputs= "text",
|
| 25 |
+
title= "BrainBox API Core"
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# Mount FastAPI inside Gradio!
|
| 29 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path= "/" )
|
| 30 |
+
|
| 31 |
+
# CRITICAL FIX: Explicitly launch the Uvicorn server to keep the container running
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|