Spaces:
Runtime error
Runtime error
Commit ·
7211a24
1
Parent(s): dfb120d
Fixed OCR submit error by changing to button click event
Browse files
app.py
CHANGED
|
@@ -50,9 +50,7 @@ preprocess = transforms.Compose(
|
|
| 50 |
)
|
| 51 |
|
| 52 |
# Load ImageNet class labels
|
| 53 |
-
|
| 54 |
-
# Load ImageNet class labels mapping
|
| 55 |
-
imagenet_labels = []
|
| 56 |
with open("imagenet_classes.txt", "r") as f: # ensure this file is in your folder
|
| 57 |
imagenet_labels = [s.strip() for s in f.readlines()]
|
| 58 |
|
|
@@ -191,27 +189,24 @@ with gr.Blocks() as demo:
|
|
| 191 |
outputs=gr.File(label="Download PDF Report")
|
| 192 |
)
|
| 193 |
|
|
|
|
| 194 |
# ------------------ OCR Tab ------------------
|
| 195 |
with gr.Tab("OCR"):
|
| 196 |
ocr_input = gr.Image(type="pil", label="Upload image for OCR")
|
|
|
|
| 197 |
ocr_output = gr.JSON(label="OCR Results")
|
| 198 |
pdf_button_ocr = gr.Button("Download OCR PDF")
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
ocr_button.click(
|
| 204 |
-
fn=ocr_image,
|
| 205 |
-
inputs=ocr_input,
|
| 206 |
-
outputs=ocr_output
|
| 207 |
-
)
|
| 208 |
-
|
| 209 |
pdf_button_ocr.click(
|
| 210 |
fn=lambda x: generate_pdf(x),
|
| 211 |
inputs=ocr_output,
|
| 212 |
outputs=gr.File(label="Download PDF Report"),
|
| 213 |
)
|
| 214 |
|
|
|
|
|
|
|
| 215 |
# ------------------------------
|
| 216 |
# 5. Launch the App
|
| 217 |
# ------------------------------
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
# Load ImageNet class labels
|
| 53 |
+
|
|
|
|
|
|
|
| 54 |
with open("imagenet_classes.txt", "r") as f: # ensure this file is in your folder
|
| 55 |
imagenet_labels = [s.strip() for s in f.readlines()]
|
| 56 |
|
|
|
|
| 189 |
outputs=gr.File(label="Download PDF Report")
|
| 190 |
)
|
| 191 |
|
| 192 |
+
|
| 193 |
# ------------------ OCR Tab ------------------
|
| 194 |
with gr.Tab("OCR"):
|
| 195 |
ocr_input = gr.Image(type="pil", label="Upload image for OCR")
|
| 196 |
+
ocr_button = gr.Button("Extract Text (OCR)")
|
| 197 |
ocr_output = gr.JSON(label="OCR Results")
|
| 198 |
pdf_button_ocr = gr.Button("Download OCR PDF")
|
| 199 |
|
| 200 |
+
ocr_button.click(fn=ocr_image, inputs=ocr_input, outputs=ocr_output)
|
| 201 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
pdf_button_ocr.click(
|
| 203 |
fn=lambda x: generate_pdf(x),
|
| 204 |
inputs=ocr_output,
|
| 205 |
outputs=gr.File(label="Download PDF Report"),
|
| 206 |
)
|
| 207 |
|
| 208 |
+
|
| 209 |
+
|
| 210 |
# ------------------------------
|
| 211 |
# 5. Launch the App
|
| 212 |
# ------------------------------
|