import gradio as gr from brain import img2txt, generate_story import os def generate_story_from_image(image): # Save the uploaded image temporarily temp_image_path = "temp_image.jpg" image.save(temp_image_path) # Generate text from the image scenario = img2txt(temp_image_path) # Generate a story based on the scenario story = generate_story(scenario) # Remove the temporary image file os.remove(temp_image_path) return story # Create the Gradio interface iface = gr.Interface( fn=generate_story_from_image, inputs=gr.Image(type="pil"), outputs="text", title="Kids Story Generator", description="Upload an image and get a kids story based on it!", examples=[["example_image.jpg"]], ) # Launch the app if __name__ == "__main__": iface.launch()