Upload 4 files
Browse files
flying-cat-generator/app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
from utils import generate_image
|
5 |
+
|
6 |
+
def process_csv(file_obj):
|
7 |
+
df = pd.read_csv(file_obj.name)
|
8 |
+
images = []
|
9 |
+
for i, row in df.iterrows():
|
10 |
+
prompt = row['prompt']
|
11 |
+
width = int(row['width'])
|
12 |
+
height = int(row['height'])
|
13 |
+
image = generate_image(prompt, width, height)
|
14 |
+
images.append((prompt, image))
|
15 |
+
return images
|
16 |
+
|
17 |
+
demo = gr.Interface(
|
18 |
+
fn=process_csv,
|
19 |
+
inputs=gr.File(file_types=[".csv"], label="Upload CSV File"),
|
20 |
+
outputs=gr.Gallery(label="Generated Images").style(grid=3),
|
21 |
+
title="Flying Cat Story Generator",
|
22 |
+
description="Upload a CSV file with prompts and image size to generate DALL·E-style illustrations."
|
23 |
+
)
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
demo.launch()
|
flying-cat-generator/examples/flying_cat_story_prompts.csv
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
prompt,width,height
|
2 |
+
"A futuristic dream machine glowing in a dark room, with wires and holograms swirling around.",576,1024
|
3 |
+
"A curious boy peeking into the dream machine with wide, sparkling eyes.",576,1024
|
4 |
+
"The boy presses a big glowing button on the dream machine, causing it to shake with colorful sparks.",576,1024
|
5 |
+
"A magical portal opens from the machine, revealing a galaxy with stars and floating clouds.",576,1024
|
6 |
+
"A flying cat emerges from the portal, leaving a trail of glitter behind.",576,1024
|
7 |
+
"The boy laughs joyfully, reaching out to the flying cat.",576,1024
|
8 |
+
"The boy and cat hover above the ground, spinning in a dreamlike dance.",576,1024
|
9 |
+
They fly over a floating city with neon lights and transparent buildings.,576,1024
|
10 |
+
The boy and cat ride a rainbow bridge between floating mountains in the sky.,576,1024
|
11 |
+
They land on a candy-colored island with bouncing jelly trees.,576,1024
|
12 |
+
The island starts shaking—it's a dream quake! Everything is floating.,576,1024
|
13 |
+
A tornado made of pillows and feathers chases them across the sky.,576,1024
|
14 |
+
The boy protects the flying cat by holding it close and jumping into a cloud bunker.,576,1024
|
15 |
+
They emerge safely and hug tightly under a glowing moon.,576,1024
|
16 |
+
The boy and cat rest on a floating bed drifting over space.,576,1024
|
17 |
+
A glitch in the dream shows scary shadows trying to enter.,576,1024
|
18 |
+
"The cat meows loudly, forming a protective bubble around them.",576,1024
|
19 |
+
The bubble bursts into stars that scare away the shadows.,576,1024
|
20 |
+
They ride a comet trail to escape the collapsing dream world.,576,1024
|
21 |
+
The dream machine starts to break—cracks form in the space fabric.,576,1024
|
22 |
+
The boy hugs the cat tightly as they fall back through the portal.,576,1024
|
23 |
+
They crash softly onto the boy’s real bed—surrounded by glowing stardust.,576,1024
|
24 |
+
The cat purrs and turns into a plush toy in the boy’s arms.,576,1024
|
25 |
+
"The boy smiles and pulls the toy close, eyes sleepy but happy.",576,1024
|
26 |
+
The stars twinkle through the bedroom window as they sleep together.,576,1024
|
flying-cat-generator/requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
gradio
|
3 |
+
diffusers
|
4 |
+
transformers
|
5 |
+
torch
|
6 |
+
Pillow
|
flying-cat-generator/utils.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from PIL import Image, ImageDraw, ImageFont
|
3 |
+
|
4 |
+
def generate_image(prompt, width=576, height=1024):
|
5 |
+
# 模拟图像生成:用提示词生成一张带文字的占位图
|
6 |
+
img = Image.new("RGB", (width, height), color=(255, 255, 240))
|
7 |
+
draw = ImageDraw.Draw(img)
|
8 |
+
text = "\n".join(prompt[i:i+30] for i in range(0, len(prompt), 30))
|
9 |
+
draw.text((10, 10), text, fill=(20, 20, 20))
|
10 |
+
return img
|