Spaces:
Sleeping
Sleeping
manishw7 commited on
Commit ·
a6259a8
1
Parent(s): e4fa725
Robust: Monkey-patch Gradio API schema bug
Browse files
README.md
CHANGED
|
@@ -17,7 +17,7 @@ datasets:
|
|
| 17 |
- c3rl/IIIT-INDIC-HW-WORDS-Hindi
|
| 18 |
sdk: gradio
|
| 19 |
sdk_version: "4.44.1"
|
| 20 |
-
python_version: "3.
|
| 21 |
app_file: app.py
|
| 22 |
pinned: true
|
| 23 |
---
|
|
|
|
| 17 |
- c3rl/IIIT-INDIC-HW-WORDS-Hindi
|
| 18 |
sdk: gradio
|
| 19 |
sdk_version: "4.44.1"
|
| 20 |
+
python_version: "3.10"
|
| 21 |
app_file: app.py
|
| 22 |
pinned: true
|
| 23 |
---
|
app.py
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from PIL import Image
|
|
@@ -6,7 +22,6 @@ from transformers import AutoTokenizer, TrOCRProcessor, ViTImageProcessor, Visio
|
|
| 6 |
|
| 7 |
# Configuration
|
| 8 |
BASE_MODEL_ID = "paudelanil/trocr-devanagari-2"
|
| 9 |
-
# Ensuring the HF Username is correct
|
| 10 |
ADAPTER_ID = "manishw10/devgen-trocr-devanagari-lora"
|
| 11 |
|
| 12 |
print("System: Loading model components...")
|
|
@@ -38,18 +53,16 @@ def predict(image):
|
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error during inference: {str(e)}"
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
# This avoids the complex nested blocks that trigger the Gradio 4.x schema bug
|
| 43 |
demo = gr.Interface(
|
| 44 |
fn=predict,
|
| 45 |
-
inputs=gr.Image(type="pil", label="Devanagari
|
| 46 |
outputs=gr.Textbox(label="Recognized Text"),
|
| 47 |
-
title="DevGen OCR
|
| 48 |
description="Handwritten Devanagari word recognition.",
|
| 49 |
allow_flagging="never"
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
# --- ROBUST MONKEY-PATCH FOR GRADIO SCHEMA BUG ---
|
| 5 |
+
# This bypasses the 'TypeError: argument of type bool is not iterable'
|
| 6 |
+
# that occurs in Gradio 4.x/5.x internal API generation.
|
| 7 |
+
try:
|
| 8 |
+
import gradio.blocks
|
| 9 |
+
def robust_get_api_info(self):
|
| 10 |
+
return {"root": "/", "endpoints": {}}
|
| 11 |
+
gradio.blocks.Blocks.get_api_info = robust_get_api_info
|
| 12 |
+
print("System: Applied robust monkey-patch for Gradio API schema bug.")
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print(f"System: Failed to apply patch (non-critical): {e}")
|
| 15 |
+
# ------------------------------------------------
|
| 16 |
+
|
| 17 |
import gradio as gr
|
| 18 |
import torch
|
| 19 |
from PIL import Image
|
|
|
|
| 22 |
|
| 23 |
# Configuration
|
| 24 |
BASE_MODEL_ID = "paudelanil/trocr-devanagari-2"
|
|
|
|
| 25 |
ADAPTER_ID = "manishw10/devgen-trocr-devanagari-lora"
|
| 26 |
|
| 27 |
print("System: Loading model components...")
|
|
|
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error during inference: {str(e)}"
|
| 55 |
|
| 56 |
+
# Modern Interface with the patch protection
|
|
|
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=predict,
|
| 59 |
+
inputs=gr.Image(type="pil", label="Upload Devanagari Word"),
|
| 60 |
outputs=gr.Textbox(label="Recognized Text"),
|
| 61 |
+
title="DevGen OCR",
|
| 62 |
description="Handwritten Devanagari word recognition.",
|
| 63 |
allow_flagging="never"
|
| 64 |
)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
# Launch on standard HF port
|
| 68 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|