Spaces:
Runtime error
Runtime error
Austin Gatlin
commited on
Commit
•
e82c354
1
Parent(s):
7d6f2b2
try even easier way to use trocr
Browse files
app.py
CHANGED
@@ -1,19 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
-
from PIL import Image
|
4 |
|
5 |
-
|
6 |
-
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-small-handwritten')
|
7 |
-
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-small-handwritten')
|
8 |
-
|
9 |
-
# Define the prediction function
|
10 |
-
def ocr(image):
|
11 |
-
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
12 |
-
generated_ids = model.generate(pixel_values)
|
13 |
-
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
14 |
-
return generated_text
|
15 |
-
|
16 |
-
# Create a Gradio interface
|
17 |
-
demo = gr.Interface(fn=ocr, inputs="image", outputs="text")
|
18 |
-
demo.launch()
|
19 |
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
gr.load("models/microsoft/trocr-small-handwritten").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|