sumau commited on
Commit
7975e87
·
verified ·
1 Parent(s): 8be78b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
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()