Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
|
4 |
from PIL import Image
|
5 |
|
6 |
#client = InferenceClient("models/microsoft/trocr-base-handwritten")
|
|
|
|
|
7 |
|
8 |
def sepia(input_img):
|
9 |
sepia_filter = np.array([
|
@@ -21,8 +23,6 @@ def sepia(input_img):
|
|
21 |
## required positional arguments: 'inputs' and 'outputs'
|
22 |
def process_image(image):
|
23 |
try:
|
24 |
-
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-handwritten')
|
25 |
-
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-handwritten')
|
26 |
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
27 |
|
28 |
generated_ids = model.generate(pixel_values)
|
@@ -45,7 +45,7 @@ with gr.Blocks() as generated_output:
|
|
45 |
outputs=[output_img, sepia_values_text],
|
46 |
show_progress="full")
|
47 |
with gr.Row():
|
48 |
-
|
49 |
fn=process_image,
|
50 |
inputs=output_img,
|
51 |
outputs=gr.Textbox(label="Recognized Text"),
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
#client = InferenceClient("models/microsoft/trocr-base-handwritten")
|
7 |
+
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-handwritten')
|
8 |
+
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-handwritten')
|
9 |
|
10 |
def sepia(input_img):
|
11 |
sepia_filter = np.array([
|
|
|
23 |
## required positional arguments: 'inputs' and 'outputs'
|
24 |
def process_image(image):
|
25 |
try:
|
|
|
|
|
26 |
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
27 |
|
28 |
generated_ids = model.generate(pixel_values)
|
|
|
45 |
outputs=[output_img, sepia_values_text],
|
46 |
show_progress="full")
|
47 |
with gr.Row():
|
48 |
+
output_img.change(
|
49 |
fn=process_image,
|
50 |
inputs=output_img,
|
51 |
outputs=gr.Textbox(label="Recognized Text"),
|