RAMYASRI-39 commited on
Commit
5d80cb7
·
verified ·
1 Parent(s): 6c3ee9c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
25
+ interface = gr.Interface(
26
+ fn=process_image,
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
34
+ if __name__ == "__main__":
35
+ interface.launch()