Princeaka commited on
Commit
2f17124
·
verified ·
1 Parent(s): 2688b9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -1,8 +1,8 @@
1
- # app.py — Full multimodal FastAPI + Gradio (Hugging Face Spaces compatible)
2
  import os
3
  import shutil
4
  import asyncio
5
  import inspect
 
6
  from typing import Optional
7
  from fastapi import FastAPI, UploadFile, File, Form
8
  from fastapi.responses import JSONResponse
@@ -39,6 +39,13 @@ async def call_ai(fn, *args, **kwargs):
39
  return await fn(*args, **kwargs)
40
  return await asyncio.to_thread(lambda: fn(*args, **kwargs))
41
 
 
 
 
 
 
 
 
42
  # --- FastAPI app ---
43
  app = FastAPI(title="Multimodal Module API")
44
 
@@ -178,4 +185,10 @@ with gr.Blocks(title="Multimodal Bot (UI)") as demo:
178
  gr.Button("Send").click(gradio_text_fn, [inp, uid, lang], out)
179
 
180
  # Mount Gradio to FastAPI
181
- app = gr.mount_gradio_app(app, demo, path="/")
 
 
 
 
 
 
 
 
1
  import os
2
  import shutil
3
  import asyncio
4
  import inspect
5
+ import socket
6
  from typing import Optional
7
  from fastapi import FastAPI, UploadFile, File, Form
8
  from fastapi.responses import JSONResponse
 
39
  return await fn(*args, **kwargs)
40
  return await asyncio.to_thread(lambda: fn(*args, **kwargs))
41
 
42
+ def get_free_port():
43
+ s = socket.socket()
44
+ s.bind(("", 0))
45
+ port = s.getsockname()[1]
46
+ s.close()
47
+ return port
48
+
49
  # --- FastAPI app ---
50
  app = FastAPI(title="Multimodal Module API")
51
 
 
185
  gr.Button("Send").click(gradio_text_fn, [inp, uid, lang], out)
186
 
187
  # Mount Gradio to FastAPI
188
+ app = gr.mount_gradio_app(app, demo, path="/")
189
+
190
+ # --- Local Run Only ---
191
+ if __name__ == "__main__":
192
+ import uvicorn
193
+ port = int(os.environ.get("PORT", get_free_port()))
194
+ uvicorn.run("app:app", host="0.0.0.0", port=port, reload=True)