calcfastapi / app.py
0Learn's picture
Update app.py
3f68f5c verified
raw
history blame
819 Bytes
import gradio as gr
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from backend import router as backend_router
from frontend import create_interface
import os
# Create the main FastAPI app
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include the backend routes
app.include_router(backend_router)
# Create the Gradio interface
iface = create_interface()
# Mount the Gradio app
app = gr.mount_gradio_app(app, iface, path="/")
# Hugging Face Spaces provides the port number in the PORT environment variable
port = int(os.environ.get("PORT", 7860))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=port)