Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import easyocr
|
| 3 |
+
|
| 4 |
+
# Initialize the EasyOCR Reader
|
| 5 |
+
reader = easyocr.Reader(['en'], gpu=False) # Set gpu=True if GPU is available
|
| 6 |
+
|
| 7 |
+
def extract_text_from_image(image):
|
| 8 |
+
# Perform OCR on the image
|
| 9 |
+
results = reader.readtext(image)
|
| 10 |
+
|
| 11 |
+
# Extract detected text
|
| 12 |
+
extracted_text = "\n".join([result[1] for result in results])
|
| 13 |
+
|
| 14 |
+
return extracted_text
|
| 15 |
+
|
| 16 |
+
# Define Gradio Interface
|
| 17 |
+
interface = gr.Interface(
|
| 18 |
+
fn=extract_text_from_image, # Function to run
|
| 19 |
+
inputs=gr.Image(type="filepath"), # Upload an image
|
| 20 |
+
outputs="text", # Display extracted text
|
| 21 |
+
title="Image Text Extractor",
|
| 22 |
+
description="Upload an image to extract text using OCR."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the app
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
interface.launch()
|