Commit
·
53edb88
1
Parent(s):
83bc1b9
Updated with OCR model and Gradio integration
Browse files- app.py +5 -5
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,20 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load Hugging Face
|
5 |
ocr_model = pipeline('image-to-text', model='microsoft/trocr-base-printed')
|
6 |
|
7 |
def analyze_image(image):
|
8 |
-
|
9 |
-
result
|
10 |
|
11 |
# Gradio interface for image input
|
12 |
demo = gr.Interface(
|
13 |
fn=analyze_image,
|
14 |
inputs=gr.Image(type="pil"), # Upload an image
|
15 |
outputs="text", # Output the extracted text
|
16 |
-
title="
|
17 |
-
description="Upload an image of
|
18 |
)
|
19 |
|
20 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load a Hugging Face OCR model for printed text
|
5 |
ocr_model = pipeline('image-to-text', model='microsoft/trocr-base-printed')
|
6 |
|
7 |
def analyze_image(image):
|
8 |
+
result = ocr_model(image)
|
9 |
+
return result[0]['generated_text'] if result else "No text could be extracted."
|
10 |
|
11 |
# Gradio interface for image input
|
12 |
demo = gr.Interface(
|
13 |
fn=analyze_image,
|
14 |
inputs=gr.Image(type="pil"), # Upload an image
|
15 |
outputs="text", # Output the extracted text
|
16 |
+
title="Invoice Text Extraction",
|
17 |
+
description="Upload an image of an invoice to extract text."
|
18 |
)
|
19 |
|
20 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ transformers
|
|
3 |
torch
|
4 |
gradio
|
5 |
datasets
|
6 |
-
pytesseract
|
|
|
|
3 |
torch
|
4 |
gradio
|
5 |
datasets
|
6 |
+
pytesseract
|
7 |
+
Pillow
|