Delete app.py
Browse files
app.py
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import json
|
3 |
-
from transformers import pipeline
|
4 |
-
from PIL import Image
|
5 |
-
import os
|
6 |
-
import spaces
|
7 |
-
|
8 |
-
# Text Expansion Model (ZeroGPU-compatible)
|
9 |
-
text_generator = pipeline("text2text-generation", model="t5-base")
|
10 |
-
|
11 |
-
# Image Generation Model (ZeroGPU-compatible)
|
12 |
-
image_generator = pipeline("text-to-image", model="stabilityai/sdxl-turbo")
|
13 |
-
|
14 |
-
@spaces.GPU
|
15 |
-
def generate_cartoon(script_text):
|
16 |
-
# Step 1: Generate scene breakdown
|
17 |
-
prompt = f"""
|
18 |
-
Convert this cartoon story into a structured scene list in JSON format. For each scene include:
|
19 |
-
1. "scene_description"
|
20 |
-
2. "dialogue"
|
21 |
-
3. "characters"
|
22 |
-
4. "background_description"
|
23 |
-
|
24 |
-
Story: {script_text}
|
25 |
-
Return as: {{ "scenes": [{{ ... }}] }}
|
26 |
-
"""
|
27 |
-
|
28 |
-
try:
|
29 |
-
result = text_generator(prompt, max_new_tokens=1024)[0]['generated_text']
|
30 |
-
scene_data = json.loads(result)
|
31 |
-
except Exception as e:
|
32 |
-
return f"Failed to generate structured scenes. Error: {e}"
|
33 |
-
|
34 |
-
os.makedirs("generated_images", exist_ok=True)
|
35 |
-
|
36 |
-
results = []
|
37 |
-
for idx, scene in enumerate(scene_data.get("scenes", [])):
|
38 |
-
# Generate background image
|
39 |
-
bg_prompt = scene.get("background_description", "cartoon background, colorful")
|
40 |
-
image = image_generator(bg_prompt, guidance_scale=7.5, num_inference_steps=25).images[0]
|
41 |
-
image_path = f"generated_images/scene_{idx+1}.png"
|
42 |
-
image.save(image_path)
|
43 |
-
|
44 |
-
# Collect image and dialogue
|
45 |
-
dialogue = scene.get("dialogue", "")
|
46 |
-
results.append((image_path, f"Scene {idx+1} Dialogue:\n{dialogue}"))
|
47 |
-
|
48 |
-
return results
|
49 |
-
|
50 |
-
|
51 |
-
# Gradio Interface
|
52 |
-
demo = gr.Interface(
|
53 |
-
fn=generate_cartoon,
|
54 |
-
inputs=gr.Textbox(label="Enter Cartoon Script", lines=10, placeholder="Once upon a time..."),
|
55 |
-
outputs=gr.Gallery(label="Generated Scenes with Dialogues", columns=1, type="auto"),
|
56 |
-
title="Cartoon Film Generator (ZeroGPU)",
|
57 |
-
description="Enter a cartoon story. This tool will break it into scenes, generate background images, and show dialogues. Audio and video creation should be done in Colab."
|
58 |
-
)
|
59 |
-
|
60 |
-
if __name__ == "__main__":
|
61 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|