Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,10 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
5 |
-
import torch
|
6 |
|
7 |
# Initialize the model and processor
|
8 |
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten")
|
9 |
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwritten")
|
10 |
-
model.eval()
|
11 |
|
12 |
def display_sketch(sketch):
|
13 |
if isinstance(sketch, dict) and 'composite' in sketch:
|
@@ -38,8 +36,14 @@ with gr.Blocks() as demo:
|
|
38 |
output_image = gr.Image(label="Your Sketch")
|
39 |
recognized_text = gr.Textbox(label="Recognized Text")
|
40 |
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Launch the demo
|
45 |
demo.launch()
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
|
|
5 |
|
6 |
# Initialize the model and processor
|
7 |
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten")
|
8 |
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwritten")
|
|
|
9 |
|
10 |
def display_sketch(sketch):
|
11 |
if isinstance(sketch, dict) and 'composite' in sketch:
|
|
|
36 |
output_image = gr.Image(label="Your Sketch")
|
37 |
recognized_text = gr.Textbox(label="Recognized Text")
|
38 |
|
39 |
+
def process_and_recognize(sketch):
|
40 |
+
image_path = display_sketch(sketch)
|
41 |
+
if image_path:
|
42 |
+
text = recognize_text(image_path)
|
43 |
+
return image_path, text
|
44 |
+
return None, ""
|
45 |
+
|
46 |
+
sketchpad.change(process_and_recognize, inputs=sketchpad, outputs=[output_image, recognized_text])
|
47 |
|
48 |
# Launch the demo
|
49 |
demo.launch()
|