import gradio as gr from transformers import pipeline # Initialize the image-to-text pipeline extractor = pipeline("image-to-text", model="microsoft/git-base-textcaps") def extract_text(image): result = extractor(image) return result[0]['generated_text'] # Create the Gradio interface iface = gr.Interface( fn=extract_text, inputs=gr.Image(type="pil"), outputs="text", title="Image Text Extractor", description="Upload an image to extract text using Hugging Face's image-to-text model." ) # Launch the app iface.launch()