Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load the
|
5 |
-
ocr_model = pipeline("image-to-text", model="microsoft/
|
6 |
|
7 |
-
def
|
8 |
-
#
|
9 |
-
|
10 |
-
return text
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
fn=
|
15 |
-
inputs=gr.Image(type="
|
16 |
-
outputs="text",
|
17 |
-
title="
|
18 |
-
description="Upload an image to
|
19 |
)
|
20 |
|
21 |
-
# Launch the
|
22 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the OCR model
|
5 |
+
ocr_model = pipeline("image-to-text", model="microsoft/trocr-large-printed")
|
6 |
|
7 |
+
def recognize_text(image):
|
8 |
+
# Use the model on the input image
|
9 |
+
result = ocr_model(image)
|
10 |
+
return result[0]['generated_text'] # Return the recognized text
|
11 |
|
12 |
+
# Set up the Gradio interface
|
13 |
+
interface = gr.Interface(
|
14 |
+
fn=recognize_text,
|
15 |
+
inputs=gr.Image(type="filepath"), # Use filepath to accept image input
|
16 |
+
outputs="text", # Output the recognized text
|
17 |
+
title="OCR with Trocr",
|
18 |
+
description="Upload an image to recognize text using the Trocr model."
|
19 |
)
|
20 |
|
21 |
+
# Launch the app
|
22 |
+
if __name__ == "__main__":
|
23 |
+
interface.launch()
|