blasisd commited on
Commit
999a8f6
·
1 Parent(s): 984f501

Allow cross-origin requests

Browse files
Files changed (1) hide show
  1. src/main.py +10 -0
src/main.py CHANGED
@@ -1,5 +1,6 @@
1
  from contextlib import asynccontextmanager
2
  from fastapi import FastAPI
 
3
  from transformers import (
4
  AutoImageProcessor,
5
  AutoModel,
@@ -38,6 +39,15 @@ app = FastAPI(
38
  description="Mushrooms Classification API", version="0.1.0", lifespan=lifespan
39
  )
40
 
 
 
 
 
 
 
 
 
 
41
 
42
  @app.get("/")
43
  async def root():
 
1
  from contextlib import asynccontextmanager
2
  from fastapi import FastAPI
3
+ from fastapi.middleware.cors import CORSMiddleware
4
  from transformers import (
5
  AutoImageProcessor,
6
  AutoModel,
 
39
  description="Mushrooms Classification API", version="0.1.0", lifespan=lifespan
40
  )
41
 
42
+ # Allow all origins for CORS (can be restricted to specific address)
43
+ app.add_middleware(
44
+ CORSMiddleware,
45
+ allow_origins=["*"],
46
+ allow_credentials=True,
47
+ allow_methods=["*"],
48
+ allow_headers=["*"],
49
+ )
50
+
51
 
52
  @app.get("/")
53
  async def root():