Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
+
import gradio as gr # For building the web interface
|
| 3 |
+
from transformers import pipeline # To use Hugging Face models
|
| 4 |
+
|
| 5 |
+
# Load the DALL-E Mini model from Hugging Face
|
| 6 |
+
# Using pipeline to handle the model. Note: 'dalle-mini' is lightweight and CPU-friendly
|
| 7 |
+
generator = pipeline("text-to-image-generation", model="flax-community/dalle-mini")
|
| 8 |
+
|
| 9 |
+
# Function to generate comic-style panels from a user's story description
|
| 10 |
+
def generate_comic_panels(story_description):
|
| 11 |
+
# Break the story into key points (naive splitting; could use NLP techniques for better splitting)
|
| 12 |
+
scenes = story_description.split(". ")
|
| 13 |
+
|
| 14 |
+
images = []
|
| 15 |
+
for scene in scenes:
|
| 16 |
+
# Generate an image for each scene using the loaded model
|
| 17 |
+
image = generator(scene)
|
| 18 |
+
images.append(image[0]["generated_image"]) # Get the generated image from the response
|
| 19 |
+
|
| 20 |
+
return images
|
| 21 |
+
|
| 22 |
+
# Set up the Gradio interface
|
| 23 |
+
# User inputs their story description, and we generate images as a comic-style series
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=generate_comic_panels, # Function to be called when the user interacts
|
| 26 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter your short story description here..."), # User input
|
| 27 |
+
outputs=gr.Gallery(label="Generated Comic Panels").style(grid=[2]), # Display images in a gallery format
|
| 28 |
+
title="GenArt Narrative",
|
| 29 |
+
description="Enter a short story description, and we'll transform it into a comic strip!"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Launch the app
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|
| 35 |
+
|