jomasego commited on
Commit
50ca028
·
1 Parent(s): 38deffc

Refactor: Use top-level Starlette app in main_asgi

Browse files
Files changed (1) hide show
  1. modal_whisper_app.py +15 -5
modal_whisper_app.py CHANGED
@@ -1,5 +1,7 @@
1
  import modal
2
  from fastapi import FastAPI, UploadFile, File, Body, Query
 
 
3
  import os
4
  import tempfile
5
  import io # Used by Whisper for BytesIO
@@ -826,9 +828,17 @@ def video_analyzer_gradio_ui():
826
  # === Main ASGI App (FastAPI + Gradio) ===
827
  @modal.asgi_app()
828
  def main_asgi():
829
- # fastapi_app is defined globally
830
- # video_analyzer_gradio_ui returns an ASGI-compatible Gradio app
831
  gradio_asgi_app = video_analyzer_gradio_ui()
832
- fastapi_app.mount("/gradio", gradio_asgi_app, name="gradio_ui")
833
- print("FastAPI app with Gradio UI mounted on /gradio is ready.")
834
- return fastapi_app
 
 
 
 
 
 
 
 
 
 
 
1
  import modal
2
  from fastapi import FastAPI, UploadFile, File, Body, Query
3
+ from starlette.applications import Starlette
4
+ from starlette.routing import Mount
5
  import os
6
  import tempfile
7
  import io # Used by Whisper for BytesIO
 
828
  # === Main ASGI App (FastAPI + Gradio) ===
829
  @modal.asgi_app()
830
  def main_asgi():
 
 
831
  gradio_asgi_app = video_analyzer_gradio_ui()
832
+
833
+ # fastapi_app is already defined globally and has its routes (@fastapi_app.post, @fastapi_app.get)
834
+ # We should not mount Gradio inside fastapi_app if we are mounting fastapi_app itself into a Starlette app.
835
+ # Ensure fastapi_app is 'clean' of the /gradio mount if it was done elsewhere,
836
+ # or ensure it's not mounted if we are doing it at the Starlette level.
837
+ # For this change, we assume fastapi_app does NOT have /gradio mounted internally.
838
+
839
+ # Create a new top-level Starlette app
840
+ top_level_app = Starlette(routes=[
841
+ Mount("/api", app=fastapi_app), # Mount FastAPI app under /api
842
+ Mount("/gradio", app=gradio_asgi_app) # Mount Gradio app under /gradio
843
+ ])
844
+ return top_level_app