File size: 1,173 Bytes
dc2831e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
import requests
import imageio
from PIL import Image

# Function to download image based on prompt
def download_image(prompt, index):
    url = f"https://pollinations.ai/p/{prompt}"
    response = requests.get(url)
    image_filename = f'generated_image_{index}.jpg'
    with open(image_filename, 'wb') as file:
        file.write(response.content)
    return image_filename

# Function to visualize each line of the story
def visualize_story_lines(story):
    lines = story.split('\n')  # Split story into lines
    images = []
    
    for idx, line in enumerate(lines):
        prompt = line.replace(" ", "_")  # You can adjust prompt formatting
        img_file = download_image(prompt, idx)
        images.append(imageio.imread(img_file))  # Append image to list
    
    # Create a GIF as a slideshow from the images
    gif_filename = 'slideshow.gif'
    imageio.mimsave(gif_filename, images, duration=1)  # 1 second per image
    return gif_filename

# Gradio interface
def visualize_story_slideshow(story):
    return visualize_story_lines(story)

iface = gr.Interface(fn=visualize_story_slideshow, inputs="text", outputs="file")
iface.launch()