|
from fastapi import FastAPI, HTTPException |
|
from pydantic import BaseModel |
|
import requests |
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
|
app = FastAPI() |
|
|
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=["*"], |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
|
|
|
|
class TryOnRequest(BaseModel): |
|
humanImg: str |
|
garment: str |
|
garmentDesc: str |
|
category: str |
|
|
|
|
|
@app.post("/try-on") |
|
async def try_on(request: TryOnRequest): |
|
url = "https://changeclothesai.online/api/try-on/edge" |
|
|
|
headers = { |
|
"accept": "*/*", |
|
"f": "sdfdsfsKaVgUoxa5j1jzcFtziPx", |
|
} |
|
|
|
data = { |
|
"humanImg": request.humanImg, |
|
"garment": request.garment, |
|
"garmentDesc": request.garmentDesc, |
|
"category": request.category |
|
} |
|
|
|
try: |
|
response = requests.post(url, headers=headers, cookies={}, data=data) |
|
response.raise_for_status() |
|
|
|
return { |
|
"status_code": response.status_code, |
|
"response": response.json() if response.headers.get('content-type') == 'application/json' else response.text |
|
} |
|
except requests.exceptions.RequestException as e: |
|
raise HTTPException(status_code=500, detail=f"Error forwarding request: {str(e)}") |
|
|
|
|
|
@app.get("/") |
|
async def root(): |
|
return {"message": "FastAPI proxy for try-on API is running"} |