Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,41 +2,54 @@ import gradio as gr
|
|
2 |
from modelscope.pipelines import pipeline
|
3 |
from modelscope.utils.constant import Tasks
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
7 |
|
8 |
-
def
|
9 |
"""
|
10 |
-
Generate a Pokémon
|
11 |
-
The prompt is
|
|
|
12 |
"""
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
# Prepare the
|
|
|
17 |
inputs = {'text': full_prompt, 'duration': duration}
|
18 |
if image:
|
19 |
-
inputs['image'] = image
|
20 |
|
21 |
-
# Generate the video using the ModelScope pipeline
|
22 |
result = video_model(inputs)
|
23 |
return result["output_video"]
|
24 |
|
25 |
-
# Build the Gradio UI
|
26 |
with gr.Blocks() as iface:
|
27 |
-
gr.Markdown("# 🎥 PokeVidGen
|
28 |
-
gr.Markdown(
|
29 |
-
|
|
|
|
|
30 |
with gr.Row():
|
31 |
-
prompt = gr.Textbox(
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
duration = gr.Slider(1, 10, step=1, label="Video Duration (Seconds)", value=5)
|
35 |
image = gr.Image(label="Upload an Image (Optional)", type="filepath")
|
|
|
|
|
36 |
|
37 |
-
generate_btn
|
38 |
-
|
39 |
-
|
40 |
-
generate_btn.click(generate_pokemon_video, inputs=[prompt, style, duration, image], outputs=output_video)
|
41 |
|
42 |
iface.launch()
|
|
|
2 |
from modelscope.pipelines import pipeline
|
3 |
from modelscope.utils.constant import Tasks
|
4 |
|
5 |
+
# Use CogVideo, a publicly available text-to-video model on Hugging Face.
|
6 |
+
# (Replace 'THUDM/CogVideo-5M' with the correct ID if needed.)
|
7 |
+
video_model = pipeline(Tasks.text_to_video_synthesis, model='THUDM/CogVideo-5M')
|
8 |
|
9 |
+
def generate_pokemon_anime_video(prompt, style, duration, image):
|
10 |
"""
|
11 |
+
Generate a Pokémon anime–themed video.
|
12 |
+
The prompt is enriched with style and context so that the model "imagines"
|
13 |
+
iconic Pokémon scenes (e.g., Ash, Pikachu, Team Rocket).
|
14 |
"""
|
15 |
+
full_prompt = (
|
16 |
+
f"{prompt}, in {style} style. "
|
17 |
+
"Include iconic Pokémon elements like Ash, Pikachu, and Team Rocket."
|
18 |
+
)
|
19 |
|
20 |
+
# Prepare inputs for the model.
|
21 |
+
# (If the model doesn't support image conditioning, the 'image' key may be ignored.)
|
22 |
inputs = {'text': full_prompt, 'duration': duration}
|
23 |
if image:
|
24 |
+
inputs['image'] = image
|
25 |
|
|
|
26 |
result = video_model(inputs)
|
27 |
return result["output_video"]
|
28 |
|
29 |
+
# Build the Gradio UI with dropdown, slider, and file upload.
|
30 |
with gr.Blocks() as iface:
|
31 |
+
gr.Markdown("# 🎥 PokeVidGen AI")
|
32 |
+
gr.Markdown(
|
33 |
+
"Generate Pokémon anime shorts with AI! "
|
34 |
+
"Enter a scene prompt, select an animation style, set the video duration, and optionally upload an image."
|
35 |
+
)
|
36 |
with gr.Row():
|
37 |
+
prompt = gr.Textbox(
|
38 |
+
label="Enter Pokémon Scene",
|
39 |
+
placeholder="Ash battles Team Rocket with Pikachu's Thunderbolt"
|
40 |
+
)
|
41 |
+
style = gr.Dropdown(
|
42 |
+
["Anime Classic", "Modern 3D", "Cartoon"],
|
43 |
+
label="Animation Style",
|
44 |
+
value="Anime Classic"
|
45 |
+
)
|
46 |
duration = gr.Slider(1, 10, step=1, label="Video Duration (Seconds)", value=5)
|
47 |
image = gr.Image(label="Upload an Image (Optional)", type="filepath")
|
48 |
+
generate_btn = gr.Button("Generate Pokémon Anime Video")
|
49 |
+
output_video = gr.Video(label="Generated Video")
|
50 |
|
51 |
+
generate_btn.click(generate_pokemon_anime_video,
|
52 |
+
inputs=[prompt, style, duration, image],
|
53 |
+
outputs=output_video)
|
|
|
54 |
|
55 |
iface.launch()
|