Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,34 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
from fastapi.responses import StreamingResponse
|
|
|
|
| 3 |
from rembg import remove
|
| 4 |
import io
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
@app.post("/remove-background/")
|
| 9 |
async def remove_background(image: UploadFile = File(...)):
|
| 10 |
try:
|
| 11 |
input_bytes = await image.read()
|
| 12 |
output_bytes = remove(input_bytes)
|
| 13 |
-
|
| 14 |
return StreamingResponse(io.BytesIO(output_bytes), media_type="image/png")
|
| 15 |
except Exception as e:
|
| 16 |
raise HTTPException(status_code=500, detail=f"Error removing background: {str(e)}")
|
| 17 |
|
| 18 |
-
# Add a root endpoint for health checks
|
| 19 |
@app.get("/")
|
| 20 |
def read_root():
|
| 21 |
-
return {"status": "Backend is running"}
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
from fastapi.responses import StreamingResponse
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from rembg import remove
|
| 5 |
import io
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# --- AÑADIDO CRUCIAL ---
|
| 10 |
+
# Configurar CORS para permitir peticiones desde tu página en GitHub.
|
| 11 |
+
origins = [
|
| 12 |
+
"https://carleyinteractivestudio.github.io", # La URL de tu frontend
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
app.add_middleware(
|
| 16 |
+
CORSMiddleware,
|
| 17 |
+
allow_origins=origins,
|
| 18 |
+
allow_credentials=True,
|
| 19 |
+
allow_methods=["*"], # Permite todos los métodos (POST, GET, etc.)
|
| 20 |
+
allow_headers=["*"], # Permite todas las cabeceras
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
@app.post("/remove-background/")
|
| 24 |
async def remove_background(image: UploadFile = File(...)):
|
| 25 |
try:
|
| 26 |
input_bytes = await image.read()
|
| 27 |
output_bytes = remove(input_bytes)
|
|
|
|
| 28 |
return StreamingResponse(io.BytesIO(output_bytes), media_type="image/png")
|
| 29 |
except Exception as e:
|
| 30 |
raise HTTPException(status_code=500, detail=f"Error removing background: {str(e)}")
|
| 31 |
|
|
|
|
| 32 |
@app.get("/")
|
| 33 |
def read_root():
|
| 34 |
+
return {"status": "VidSpri Backend is running"}
|