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