Spaces:
Running
Running
Update app.py
Browse filesApi mounted with gradio server
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 |
-
|
|
|
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)
|