from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware app.add_middleware( CORSMiddleware, allow_origins=["*"], # Allow all origins for simplicity, or specify domains allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Define FastAPI app app = FastAPI() # Basic GET endpoint @app.get("/") def read_root(): return {"message": "Welcome to the FastAPI app on Hugging Face Spaces!"} # If running as the main module, start Uvicorn if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=7860)