Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -19,6 +19,15 @@ def load_model():
|
|
| 19 |
model = Model(device='cuda' if torch.cuda.is_available() else 'cpu')
|
| 20 |
model.load_model('cartoon1')
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@app.post("/upload/")
|
| 23 |
async def process_image(file: UploadFile = File(...), top: int = Form(...), bottom: int = Form(...), left: int = Form(...), right: int = Form(...)):
|
| 24 |
global model
|
|
@@ -46,11 +55,3 @@ async def process_image(file: UploadFile = File(...), top: int = Form(...), bott
|
|
| 46 |
return StreamingResponse(BytesIO(encoded_image.tobytes()), media_type="image/jpeg")
|
| 47 |
|
| 48 |
|
| 49 |
-
# Mount static files directory
|
| 50 |
-
app.mount("/", StaticFiles(directory="AB", html=True), name="static")
|
| 51 |
-
|
| 52 |
-
# Define index route
|
| 53 |
-
@app.get("/")
|
| 54 |
-
def index():
|
| 55 |
-
return FileResponse(path="/app/AB/index.html", media_type="text/html")
|
| 56 |
-
|
|
|
|
| 19 |
model = Model(device='cuda' if torch.cuda.is_available() else 'cpu')
|
| 20 |
model.load_model('cartoon1')
|
| 21 |
|
| 22 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 23 |
+
|
| 24 |
+
app.add_middleware(
|
| 25 |
+
CORSMiddleware,
|
| 26 |
+
allow_origins=["*"], # Adjust as needed, '*' allows requests from any origin
|
| 27 |
+
allow_credentials=True,
|
| 28 |
+
allow_methods=["*"],
|
| 29 |
+
allow_headers=["*"],
|
| 30 |
+
)
|
| 31 |
@app.post("/upload/")
|
| 32 |
async def process_image(file: UploadFile = File(...), top: int = Form(...), bottom: int = Form(...), left: int = Form(...), right: int = Form(...)):
|
| 33 |
global model
|
|
|
|
| 55 |
return StreamingResponse(BytesIO(encoded_image.tobytes()), media_type="image/jpeg")
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|