Spaces:
Sleeping
Sleeping
File size: 1,344 Bytes
b8869d6 3a36517 b8869d6 3a36517 b8869d6 3a36517 b8869d6 3a36517 b8869d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import gradio as gr
import requests
BACKEND_API_URL = "https://uddipan107-ocr-dimt-controller.hf.space/frontend_infer"
def ui_submit(image, json_file):
if image is None or json_file is None:
return "Please upload both an image and a NDJSON file."
# image is a file path (string), so open it in binary mode
with open(image, "rb") as img_f, open(json_file.name, "rb") as json_f:
files = {
"image_file": (image.split("/")[-1], img_f, "image/png"),
"json_file": (json_file.name, json_f, "application/json"),
}
try:
response = requests.post(BACKEND_API_URL, files=files)
if response.status_code == 200:
data = response.json()
return data.get("result") or data.get("error") or str(data)
else:
return f"Backend error {response.status_code}: {response.text}"
except Exception as e:
return f"Error calling backend: {e}"
gr.Interface(
fn=ui_submit,
inputs=[
gr.Image(type="filepath", label="Upload Image"), # <-- corrected
gr.File(label="Upload JSON (NDJSON)"),
],
outputs="text",
title="OCR Full-Stack Demo",
description="Upload an image and NDJSON. The backend forwards your files to the model API and returns the result."
).launch()
|