Spaces:
Sleeping
Sleeping
manishw7 commited on
Commit ·
39ef92c
1
Parent(s): a6259a8
Fix: Surgical patch to enable Recognize button
Browse files
app.py
CHANGED
|
@@ -1,18 +1,24 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
-
# ---
|
| 5 |
-
# This
|
| 6 |
-
#
|
| 7 |
try:
|
| 8 |
-
import
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
except Exception as e:
|
| 14 |
-
print(f"System: Failed to apply
|
| 15 |
-
# ----------------------------------------
|
| 16 |
|
| 17 |
import gradio as gr
|
| 18 |
import torch
|
|
@@ -53,16 +59,16 @@ def predict(image):
|
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error during inference: {str(e)}"
|
| 55 |
|
| 56 |
-
#
|
| 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="
|
| 63 |
allow_flagging="never"
|
| 64 |
)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
-
#
|
| 68 |
-
demo.launch(
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
# --- SURGICAL MONKEY-PATCH FOR GRADIO ---
|
| 5 |
+
# This fixes the exact internal function that crashes on 'bool' types
|
| 6 |
+
# without breaking the actual API endpoints.
|
| 7 |
try:
|
| 8 |
+
import gradio_client.utils
|
| 9 |
+
original_fn = gradio_client.utils.json_schema_to_python_type
|
| 10 |
+
|
| 11 |
+
def patched_json_schema_to_python_type(schema, *args, **kwargs):
|
| 12 |
+
# The bug happens when 'schema' is a boolean. We force it to be a dict or handle it.
|
| 13 |
+
if isinstance(schema, bool):
|
| 14 |
+
return "Any"
|
| 15 |
+
return original_fn(schema, *args, **kwargs)
|
| 16 |
+
|
| 17 |
+
gradio_client.utils.json_schema_to_python_type = patched_json_schema_to_python_type
|
| 18 |
+
print("System: Applied surgical monkey-patch for Gradio schema bug.")
|
| 19 |
except Exception as e:
|
| 20 |
+
print(f"System: Failed to apply surgical patch: {e}")
|
| 21 |
+
# ----------------------------------------
|
| 22 |
|
| 23 |
import gradio as gr
|
| 24 |
import torch
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
return f"Error during inference: {str(e)}"
|
| 61 |
|
| 62 |
+
# Simple Interface - Now protected by the surgical patch
|
| 63 |
demo = gr.Interface(
|
| 64 |
fn=predict,
|
| 65 |
+
inputs=gr.Image(type="pil", label="Upload Handwritten Devanagari Word"),
|
| 66 |
outputs=gr.Textbox(label="Recognized Text"),
|
| 67 |
+
title="DevGen Devanagari OCR",
|
| 68 |
+
description="Recognize handwritten Devanagari words using TrOCR and LoRA adaptation.",
|
| 69 |
allow_flagging="never"
|
| 70 |
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
+
# Zero-config launch is best for HF Spaces
|
| 74 |
+
demo.launch()
|