Hammedalmodel commited on
Commit
689a76d
Β·
verified Β·
1 Parent(s): 6014797

Update app.py

Browse files

Api mounted with gradio server

Files changed (1) hide show
  1. app.py +10 -31
app.py CHANGED
@@ -13,6 +13,10 @@ import uvicorn
13
  import subprocess
14
  import shutil
15
  from pathlib import Path
 
 
 
 
16
 
17
 
18
 
@@ -493,38 +497,13 @@ def create_interface():
493
 
494
  return interface
495
 
496
-
497
- def run_fastapi():
498
- uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
499
-
500
-
501
- def main():
502
- try:
503
- threading.Thread(target=run_fastapi, daemon=True).start()
504
-
505
- interface = create_interface()
506
- print("πŸš€ Starting Gradio UI on http://localhost:7860")
507
- print("🧠 FastAPI JSON endpoint available at http://localhost:8000/align")
508
-
509
- interface.launch(
510
- server_name="0.0.0.0",
511
- server_port=7860,
512
- share=False,
513
- debug=False
514
- )
515
-
516
- except ImportError as e:
517
- print("❌ Missing dependency:", e)
518
- except Exception as e:
519
- print("❌ Error launching application:", e)
520
-
521
-
522
- from fastapi import FastAPI, UploadFile, File, Form, HTTPException
523
- from fastapi.responses import JSONResponse
524
- from fastapi.middleware.cors import CORSMiddleware
525
-
526
  fastapi_app = FastAPI()
527
 
 
 
 
 
528
  fastapi_app.add_middleware(
529
  CORSMiddleware,
530
  allow_origins=["*"],
@@ -606,4 +585,4 @@ async def align_api(
606
 
607
 
608
  if __name__ == "__main__":
609
- main()
 
13
  import subprocess
14
  import shutil
15
  from pathlib import Path
16
+ from gradio.routes import mount_gradio_app
17
+ from fastapi import FastAPI, UploadFile, File, Form, HTTPException
18
+ from fastapi.responses import JSONResponse
19
+ from fastapi.middleware.cors import CORSMiddleware
20
 
21
 
22
 
 
497
 
498
  return interface
499
 
500
+ # Wrap everything in FastAPI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  fastapi_app = FastAPI()
502
 
503
+ # Mount Gradio interface
504
+ interface = create_interface()
505
+ app = mount_gradio_app(fastapi_app, interface, path="/")
506
+
507
  fastapi_app.add_middleware(
508
  CORSMiddleware,
509
  allow_origins=["*"],
 
585
 
586
 
587
  if __name__ == "__main__":
588
+ uvicorn.run(app, host="0.0.0.0", port=7860)