Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
from fastapi.responses import JSONResponse
|
3 |
+
import requests
|
4 |
+
|
5 |
+
MODEL_API_URL = "https://uddipan107-ocr-dimt-model.hf.space/infer" # Your model's API
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
@app.post("/frontend_infer")
|
10 |
+
async def frontend_infer(
|
11 |
+
image_file: UploadFile = File(...),
|
12 |
+
json_file: UploadFile = File(...),
|
13 |
+
):
|
14 |
+
files = {
|
15 |
+
"image_file": (image_file.filename, await image_file.read(), "image/png"),
|
16 |
+
"json_file": (json_file.filename, await json_file.read(), "application/json"),
|
17 |
+
}
|
18 |
+
try:
|
19 |
+
response = requests.post(MODEL_API_URL, files=files)
|
20 |
+
return JSONResponse(content=response.json(), status_code=response.status_code)
|
21 |
+
except Exception as e:
|
22 |
+
return JSONResponse(content={"error": f"Failed to contact model API: {e}"}, status_code=500)
|
23 |
+
|
24 |
+
@app.get("/")
|
25 |
+
def root():
|
26 |
+
return {"msg": "Backend proxy is up!"}
|