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()