Spaces:
Sleeping
Sleeping
Download main.py from Quantmask/Mintzy_API: direct link, hf CLI and curl.
- Browser
- Download file 891 Bytes
-
https://huggingface.co/spaces/Quantmask/Mintzy_API/resolve/main/main.py
- Command line
-
hf download hf://spaces/Quantmask/Mintzy_API/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Quantmask/Mintzy_API/resolve/main/main.py
891 Bytes
| from fastapi import FastAPI, Request, HTTPException | |
| import httpx | |
| app = FastAPI() | |
| GCP_API_URL = "http://34.63.74.181/predict" # Your GCP FastAPI endpoint | |
| 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 | |