Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from brain import img2txt, generate_story
|
3 |
+
import os
|
4 |
+
|
5 |
+
def generate_story_from_image(image):
|
6 |
+
# Save the uploaded image temporarily
|
7 |
+
temp_image_path = "temp_image.jpg"
|
8 |
+
image.save(temp_image_path)
|
9 |
+
|
10 |
+
# Generate text from the image
|
11 |
+
scenario = img2txt(temp_image_path)
|
12 |
+
|
13 |
+
# Generate a story based on the scenario
|
14 |
+
story = generate_story(scenario)
|
15 |
+
|
16 |
+
# Remove the temporary image file
|
17 |
+
os.remove(temp_image_path)
|
18 |
+
|
19 |
+
return story
|
20 |
+
|
21 |
+
# Create the Gradio interface
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=generate_story_from_image,
|
24 |
+
inputs=gr.Image(type="pil"),
|
25 |
+
outputs="text",
|
26 |
+
title="Kids Story Generator",
|
27 |
+
description="Upload an image and get a kids story based on it!",
|
28 |
+
examples=[["example_image.jpg"]],
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the app
|
32 |
+
if __name__ == "__main__":
|
33 |
+
iface.launch()
|