Pratham0100 commited on
Commit
6203ebe
·
verified ·
1 Parent(s): 468249c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -3,22 +3,27 @@ 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
  @spaces.GPU
12
- def fake_gpu_function():
13
- return "API is alive!"
14
 
15
- # Using gr.Blocks guarantees the ZeroGPU AST scanner detects the function!
16
  with gr.Blocks() as demo:
17
- gr.Markdown("# BrainBox API is Running")
18
- btn = gr.Button("Test API")
19
- out = gr.Textbox()
20
- btn.click(fn=fake_gpu_function, inputs=[], outputs=out)
 
 
 
 
 
 
 
 
 
21
 
22
- # Mount FastAPI inside Gradio! Hugging Face's runner will automatically launch this.
23
- # DO NOT CALL uvicorn.run() manually, otherwise HF's ZeroGPU middleware fails to hook!
24
- app = gr.mount_gradio_app(fastapi_app, demo, path="/")
 
3
  import gradio as gr
4
  import spaces
5
 
 
6
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "src")))
 
7
  from backend.main import app as fastapi_app
8
 
9
  @spaces.GPU
10
+ def fake_gpu():
11
+ pass
12
 
 
13
  with gr.Blocks() as demo:
14
+ gr.Markdown("BrainBox Backend is Running natively inside Gradio!")
15
+ btn = gr.Button("ZeroGPU Keepalive")
16
+ btn.click(fn=fake_gpu, inputs=[], outputs=[])
17
+
18
+ # Monkeypatch Gradio's internal FastAPI app to mount our API
19
+ original_init = gr.routes.App.__init__
20
+
21
+ def custom_init(self, *args, **kwargs):
22
+ original_init(self, *args, **kwargs)
23
+ # Mount our FastAPI app directly into Gradio's router
24
+ self.mount("/api", fastapi_app)
25
+
26
+ gr.routes.App.__init__ = custom_init
27
 
28
+ if __name__ == "__main__":
29
+ demo.launch(server_name="0.0.0.0", server_port=7860)