File size: 1,039 Bytes
5d80cb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from transformers import pipeline
import pytesseract
from PIL import Image

# Load the NLP model for text simplification
simplify_model = pipeline("summarization", model="t5-small")

def process_image(image):
    """
    Extract text from an uploaded image and simplify it.
    """
    # Extract text using Tesseract OCR
    text = pytesseract.image_to_string(Image.open(image))
    
    # Check if text is empty
    if not text.strip():
        return "No text detected in the image. Please upload a clear image of the text."

    # Simplify the extracted text
    simplified_text = simplify_model(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
    return simplified_text

# Create a Gradio interface
interface = gr.Interface(
    fn=process_image,
    inputs="image",
    outputs="text",
    title="Simplify Book Content",
    description="Upload a photo of a book page to get a simplified explanation in simple English."
)

# Launch the app
if __name__ == "__main__":
    interface.launch()