Spaces:
Sleeping
Sleeping
Commit ·
ca6ad4a
1
Parent(s): a4d1c46
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,23 +8,23 @@ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
|
| 8 |
file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 9 |
|
| 10 |
# Display the uploaded image
|
| 11 |
-
|
| 12 |
|
| 13 |
# Read the image data
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
#resized_image = image.resize((384, 384))
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
# Display the image
|
| 26 |
-
|
| 27 |
|
| 28 |
# Print the shape of the image
|
| 29 |
-
|
| 30 |
|
|
|
|
| 8 |
file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 9 |
|
| 10 |
# Display the uploaded image
|
| 11 |
+
if file is not None:
|
| 12 |
|
| 13 |
# Read the image data
|
| 14 |
+
image = Image.open(file)
|
| 15 |
+
image=image.convert("RGB")
|
| 16 |
|
| 17 |
#resized_image = image.resize((384, 384))
|
| 18 |
|
| 19 |
+
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-small-handwritten')
|
| 20 |
+
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-small-handwritten')
|
| 21 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
| 22 |
+
generated_ids = model.generate(pixel_values)
|
| 23 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 24 |
|
| 25 |
# Display the image
|
| 26 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 27 |
|
| 28 |
# Print the shape of the image
|
| 29 |
+
st.write(f"Text: {generated_text}")
|
| 30 |
|