Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import re
|
| 4 |
-
from PIL import ImageFilter
|
| 5 |
|
| 6 |
-
# Load the OCR pipeline
|
| 7 |
-
ocr_pipeline = pipeline("image-to-text", model="microsoft/trocr-
|
| 8 |
-
|
| 9 |
-
def preprocess_image(image):
|
| 10 |
-
image = image.convert('L') # Convert to grayscale
|
| 11 |
-
image = image.filter(ImageFilter.SHARPEN) # Apply some filtering
|
| 12 |
-
return image
|
| 13 |
|
| 14 |
def perform_ocr(image):
|
| 15 |
-
# Preprocess the image before OCR
|
| 16 |
-
image = preprocess_image(image)
|
| 17 |
text = ocr_pipeline(image)[0]['generated_text']
|
| 18 |
return text
|
| 19 |
|
|
@@ -53,4 +45,4 @@ def web_app():
|
|
| 53 |
interface.launch()
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
-
web_app()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import re
|
|
|
|
| 4 |
|
| 5 |
+
# Load the OCR pipeline
|
| 6 |
+
ocr_pipeline = pipeline("image-to-text", model="microsoft/trocr-base-stage1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def perform_ocr(image):
|
|
|
|
|
|
|
| 9 |
text = ocr_pipeline(image)[0]['generated_text']
|
| 10 |
return text
|
| 11 |
|
|
|
|
| 45 |
interface.launch()
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
+
web_app()
|