from fastapi import FastAPI, Request, HTTPException import httpx app = FastAPI() GCP_API_URL = "http://34.63.74.181/predict" # Your GCP FastAPI endpoint @app.post("/predict") async def predict(request: Request): try: data = await request.json() except Exception: raise HTTPException(status_code=400, detail="Invalid JSON in request body") async with httpx.AsyncClient() as client: try: response = await client.post(GCP_API_URL, json=data) response.raise_for_status() result = response.json() except httpx.RequestError as e: raise HTTPException(status_code=502, detail=f"Error contacting GCP VM: {e}") except httpx.HTTPStatusError as e: raise HTTPException(status_code=response.status_code, detail=f"GCP VM error: {response.text}") return result