RAMYASRI-39 commited on
Commit
6c351e2
·
verified ·
1 Parent(s): 56e72a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -1,24 +1,27 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- import pytesseract
4
  from PIL import Image
5
 
6
  # Load the NLP model for text simplification
7
  simplify_model = pipeline("summarization", model="t5-small")
8
 
 
 
 
9
  def process_image(image):
10
  """
11
- Extract text from an uploaded image and simplify it.
12
  """
13
- # Extract text using Tesseract OCR
14
- text = pytesseract.image_to_string(Image.open(image))
 
15
 
16
- # Check if text is empty
17
  if not text.strip():
18
  return "No text detected in the image. Please upload a clear image of the text."
19
 
20
  # Simplify the extracted text
21
- simplified_text = simplify_model(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
22
  return simplified_text
23
 
24
  # Create a Gradio interface
@@ -27,7 +30,7 @@ interface = gr.Interface(
27
  inputs="image",
28
  outputs="text",
29
  title="Simplify Book Content",
30
- description="Upload a photo of a book page to get a simplified explanation in simple English."
31
  )
32
 
33
  # Launch the app
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import easyocr
4
  from PIL import Image
5
 
6
  # Load the NLP model for text simplification
7
  simplify_model = pipeline("summarization", model="t5-small")
8
 
9
+ # Initialize EasyOCR reader
10
+ reader = easyocr.Reader(["en"])
11
+
12
  def process_image(image):
13
  """
14
+ Extract text from an uploaded image using EasyOCR and simplify it.
15
  """
16
+ # Convert image to text using EasyOCR
17
+ results = reader.readtext(image, detail=0)
18
+ text = " ".join(results)
19
 
 
20
  if not text.strip():
21
  return "No text detected in the image. Please upload a clear image of the text."
22
 
23
  # Simplify the extracted text
24
+ simplified_text = simplify_model(text, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
25
  return simplified_text
26
 
27
  # Create a Gradio interface
 
30
  inputs="image",
31
  outputs="text",
32
  title="Simplify Book Content",
33
+ description="Upload a photo of a book page to get a simplified explanation in simple English.",
34
  )
35
 
36
  # Launch the app