Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the text extraction model
|
5 |
+
ocr_model = pipeline("image-to-text", model="microsoft/monologg-ocr")
|
6 |
+
|
7 |
+
def extract_text(image):
|
8 |
+
# Perform OCR
|
9 |
+
text = ocr_model(image)[0]['generated_text']
|
10 |
+
return text
|
11 |
+
|
12 |
+
# Create the Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=extract_text,
|
15 |
+
inputs=gr.Image(type="pil"), # Accepts image input
|
16 |
+
outputs="text", # Outputs extracted text
|
17 |
+
title="Image to Text Extractor",
|
18 |
+
description="Upload an image to extract text from it."
|
19 |
+
)
|
20 |
+
|
21 |
+
# Launch the interface
|
22 |
+
iface.launch()
|