Sugamdeol commited on
Commit
dc2831e
·
verified ·
1 Parent(s): efdbfe0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import imageio
4
+ from PIL import Image
5
+
6
+ # Function to download image based on prompt
7
+ def download_image(prompt, index):
8
+ url = f"https://pollinations.ai/p/{prompt}"
9
+ response = requests.get(url)
10
+ image_filename = f'generated_image_{index}.jpg'
11
+ with open(image_filename, 'wb') as file:
12
+ file.write(response.content)
13
+ return image_filename
14
+
15
+ # Function to visualize each line of the story
16
+ def visualize_story_lines(story):
17
+ lines = story.split('\n') # Split story into lines
18
+ images = []
19
+
20
+ for idx, line in enumerate(lines):
21
+ prompt = line.replace(" ", "_") # You can adjust prompt formatting
22
+ img_file = download_image(prompt, idx)
23
+ images.append(imageio.imread(img_file)) # Append image to list
24
+
25
+ # Create a GIF as a slideshow from the images
26
+ gif_filename = 'slideshow.gif'
27
+ imageio.mimsave(gif_filename, images, duration=1) # 1 second per image
28
+ return gif_filename
29
+
30
+ # Gradio interface
31
+ def visualize_story_slideshow(story):
32
+ return visualize_story_lines(story)
33
+
34
+ iface = gr.Interface(fn=visualize_story_slideshow, inputs="text", outputs="file")
35
+ iface.launch()