Spaces:
Sleeping
Sleeping
Commit ·
948ea45
1
Parent(s): 1be646d
Initial commit with app.py and requirements.txt
Browse files- app.py +28 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import easyocr
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Initialize EasyOCR reader
|
| 6 |
+
reader = easyocr.Reader(['en', 'hi'])
|
| 7 |
+
|
| 8 |
+
# Function for OCR and search functionality
|
| 9 |
+
def process_image(image, keyword):
|
| 10 |
+
result = reader.readtext(image, detail=0)
|
| 11 |
+
extracted_text = " ".join(result)
|
| 12 |
+
|
| 13 |
+
# Check if the keyword is in the text
|
| 14 |
+
if keyword.lower() in extracted_text.lower():
|
| 15 |
+
return f"Keyword '{keyword}' found in the text.", extracted_text
|
| 16 |
+
else:
|
| 17 |
+
return f"Keyword '{keyword}' not found.", extracted_text
|
| 18 |
+
|
| 19 |
+
# Gradio interface
|
| 20 |
+
interface = gr.Interface(fn=process_image,
|
| 21 |
+
inputs=["image", "text"],
|
| 22 |
+
outputs=["text", "text"],
|
| 23 |
+
title="OCR and Document Search",
|
| 24 |
+
description="Upload an image, extract text, and search for keywords")
|
| 25 |
+
|
| 26 |
+
# Launch the app
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
easyocr
|
| 2 |
+
gradio
|
| 3 |
+
transformers
|
| 4 |
+
torch
|