Delete app.py
Browse files
app.py
DELETED
|
@@ -1,137 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from PIL import Image, ImageDraw, ImageFont
|
| 3 |
-
import io
|
| 4 |
-
import numpy as np
|
| 5 |
-
|
| 6 |
-
# ========== CONFIG ==========
|
| 7 |
-
WIDTH, HEIGHT = 1080, 1920 # 9:16 Shorts
|
| 8 |
-
SCENES = 7
|
| 9 |
-
|
| 10 |
-
# ========== CHARACTERS ==========
|
| 11 |
-
CHARS = {
|
| 12 |
-
"Chiku": {"x": 250, "y": 600, "color": (255, 100, 100)},
|
| 13 |
-
"Minnie": {"x": 500, "y": 650, "color": (100, 150, 255)},
|
| 14 |
-
"Bhootu": {"x": 750, "y": 500, "color": (255, 255, 255)}
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
def create_cartoon(prompt="Jungle Adventure"):
|
| 18 |
-
frames = []
|
| 19 |
-
|
| 20 |
-
# Story-based backgrounds
|
| 21 |
-
backgrounds = {
|
| 22 |
-
"jungle": (34,139,34),
|
| 23 |
-
"magic": (138,43,226),
|
| 24 |
-
"space": (25,25,112),
|
| 25 |
-
"default": (135,206,250)
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
bg_color = backgrounds.get(prompt.lower().split()[0], backgrounds["default"])
|
| 29 |
-
|
| 30 |
-
for i in range(SCENES * 5):
|
| 31 |
-
img = Image.new('RGB', (WIDTH, HEIGHT), bg_color)
|
| 32 |
-
draw = ImageDraw.Draw(img)
|
| 33 |
-
|
| 34 |
-
# Sky gradient
|
| 35 |
-
for y in range(HEIGHT//2):
|
| 36 |
-
r = bg_color[0] + int(y * 50 / (HEIGHT//2))
|
| 37 |
-
draw.line([(0, y), (WIDTH, y)], fill=(r, 206, 250))
|
| 38 |
-
|
| 39 |
-
# Sun/Stars
|
| 40 |
-
draw.ellipse([50, 50, 220, 220], fill=(255, 255, 0))
|
| 41 |
-
|
| 42 |
-
# ========== CHARACTERS (ALWAYS VISIBLE) ==========
|
| 43 |
-
|
| 44 |
-
# CHIKU
|
| 45 |
-
draw.ellipse([CHARS["Chiku"]["x"]-45, CHARS["Chiku"]["y"]-25,
|
| 46 |
-
CHARS["Chiku"]["x"]+45, CHARS["Chiku"]["y"]+55],
|
| 47 |
-
fill=CHARS["Chiku"]["color"])
|
| 48 |
-
draw.rectangle([CHARS["Chiku"]["x"]-30, CHARS["Chiku"]["y"]-80,
|
| 49 |
-
CHARS["Chiku"]["x"]+30, CHARS["Chiku"]["y"]-50],
|
| 50 |
-
fill=(200,40,40))
|
| 51 |
-
|
| 52 |
-
# MINNIE
|
| 53 |
-
draw.ellipse([CHARS["Minnie"]["x"]-40, CHARS["Minnie"]["y"]-20,
|
| 54 |
-
CHARS["Minnie"]["x"]+40, CHARS["Minnie"]["y"]+60],
|
| 55 |
-
fill=CHARS["Minnie"]["color"])
|
| 56 |
-
draw.rectangle([CHARS["Minnie"]["x"]-35, CHARS["Minnie"]["y"]+50,
|
| 57 |
-
CHARS["Minnie"]["x"]+35, CHARS["Minnie"]["y"]+90],
|
| 58 |
-
fill=(65,105,225))
|
| 59 |
-
|
| 60 |
-
# BHOOTU
|
| 61 |
-
draw.ellipse([CHARS["Bhootu"]["x"]-60, CHARS["Bhootu"]["y"]-40,
|
| 62 |
-
CHARS["Bhootu"]["x"]+60, CHARS["Bhootu"]["y"]+90],
|
| 63 |
-
fill=(255,255,255), outline=(173,216,230), width=10)
|
| 64 |
-
draw.ellipse([CHARS["Bhootu"]["x"]-30, CHARS["Bhootu"]["y"]-15,
|
| 65 |
-
CHARS["Bhootu"]["x"]-10, CHARS["Bhootu"]["y"]+5], fill=(0,0,0))
|
| 66 |
-
draw.ellipse([CHARS["Bhootu"]["x"]+10, CHARS["Bhootu"]["y"]-15,
|
| 67 |
-
CHARS["Bhootu"]["x"]+30, CHARS["Bhootu"]["y"]+5], fill=(0,0,0))
|
| 68 |
-
|
| 69 |
-
# NAMES (BIG)
|
| 70 |
-
font = ImageFont.load_default()
|
| 71 |
-
draw.text((CHARS["Chiku"]["x"]-40, CHARS["Chiku"]["y"]+70), "CHIKU", fill=(200,40,40), font=font)
|
| 72 |
-
draw.text((CHARS["Minnie"]["x"]-45, CHARS["Minnie"]["y"]+80), "MINNIE", fill=(65,105,225), font=font)
|
| 73 |
-
draw.text((CHARS["Bhootu"]["x"]-40, CHARS["Bhootu"]["y"]+80), "BHOOTU", fill=(100,150,255), font=font)
|
| 74 |
-
|
| 75 |
-
# STORY PROMPT DISPLAY
|
| 76 |
-
draw.rectangle([50, HEIGHT-350, WIDTH-50, HEIGHT-200], fill=(255,255,224))
|
| 77 |
-
draw.text((80, HEIGHT-330), f"Story: {prompt[:25]}...", fill=(0,0,0), font=font)
|
| 78 |
-
|
| 79 |
-
frames.append(np.array(img))
|
| 80 |
-
|
| 81 |
-
# Animated GIF
|
| 82 |
-
gif_buffer = io.BytesIO()
|
| 83 |
-
frames[0].save(gif_buffer, format='GIF', save_all=True,
|
| 84 |
-
append_images=frames[1:], duration=200, loop=0)
|
| 85 |
-
gif_buffer.seek(0)
|
| 86 |
-
return Image.open(gif_buffer), f"✅ Story: '{prompt}'\n✅ 35s 9:16 Short Ready!"
|
| 87 |
-
|
| 88 |
-
# ========== PERFECT UI WITH PROMPT ==========
|
| 89 |
-
with gr.Blocks(title="🎬 Cartoon Shorts Generator") as demo:
|
| 90 |
-
gr.Markdown("""
|
| 91 |
-
# 🎬 **Chiku + Minnie + Bhootu** - Hindi Cartoon Shorts
|
| 92 |
-
|
| 93 |
-
**1 Line Prompt** → **Perfect 9:16 Short** (35s)
|
| 94 |
-
""")
|
| 95 |
-
|
| 96 |
-
with gr.Row():
|
| 97 |
-
with gr.Column(scale=2):
|
| 98 |
-
prompt_input = gr.Textbox(
|
| 99 |
-
label="📝 1 Line Story Prompt",
|
| 100 |
-
placeholder="3 dost jungle me kho gaye...",
|
| 101 |
-
lines=2
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
generate_btn = gr.Button("🎥 GENERATE SHORT", variant="primary", size="lg")
|
| 105 |
-
|
| 106 |
-
with gr.Column(scale=1):
|
| 107 |
-
quick_prompts = gr.Dropdown(
|
| 108 |
-
choices=[
|
| 109 |
-
"3 dost jungle adventure",
|
| 110 |
-
"Magic school discovery",
|
| 111 |
-
"Time travel dinosaurs",
|
| 112 |
-
"Haunted ice cream shop",
|
| 113 |
-
"Flying cycle space trip"
|
| 114 |
-
],
|
| 115 |
-
label="Quick Stories",
|
| 116 |
-
value="3 dost jungle adventure"
|
| 117 |
-
)
|
| 118 |
-
|
| 119 |
-
with gr.Row():
|
| 120 |
-
cartoon_output = gr.Image(label="Your Cartoon Short")
|
| 121 |
-
status_output = gr.Textbox(label="Status", interactive=False)
|
| 122 |
-
|
| 123 |
-
# BUTTON EVENTS (FIXED!)
|
| 124 |
-
generate_btn.click(
|
| 125 |
-
fn=create_cartoon,
|
| 126 |
-
inputs=prompt_input,
|
| 127 |
-
outputs=[cartoon_output, status_output]
|
| 128 |
-
)
|
| 129 |
-
|
| 130 |
-
quick_prompts.change(
|
| 131 |
-
fn=lambda x: x,
|
| 132 |
-
inputs=quick_prompts,
|
| 133 |
-
outputs=prompt_input
|
| 134 |
-
)
|
| 135 |
-
|
| 136 |
-
if __name__ == "__main__":
|
| 137 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|