Spaces:
Running
Running
| from fastapi import FastAPI, APIRouter | |
| app = FastAPI(title="General Purpose API", openapi_url="/openapi.json") | |
| api_router = APIRouter() | |
| from fastapi.middleware.cors import CORSMiddleware | |
| # "http://localhost.tiangolo.com", | |
| # "https://localhost.tiangolo.com", | |
| # "http://localhost", | |
| # "http://localhost:8080", | |
| origins = [ | |
| "https://huggingface.co", | |
| "https://huggingface.co/spaces/abhijitkumarjha88192/test-space", | |
| "https://abhijitkumarjha88192-test-space.static.hf.space", | |
| "http://localhost", | |
| "http://localhost:8080", | |
| "*" | |
| ] | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def root() -> dict: | |
| """ | |
| Root GET | |
| """ | |
| return {"msg": "Hello, World!"} | |
| if __name__ == "__main__": | |
| # Use this for debugging purposes only | |
| app.include_router(api_router) | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=8001, log_level="debug") |