morbiwalaq commited on
Commit
77e44b8
·
verified ·
1 Parent(s): 605a78f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -21
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
- # Load a valid Text-to-Video model from ModelScope
6
- video_model = pipeline(Tasks.text_to_video_synthesis, model='damo-vilab/text-to-video-synthesis')
 
7
 
8
- def generate_pokemon_video(prompt, style, duration, image):
9
  """
10
- Generate a Pokémon-themed video.
11
- The prompt is augmented with the chosen style.
 
12
  """
13
- # Modify prompt with chosen style
14
- full_prompt = f"{prompt}, Pokémon style: {style}"
 
 
15
 
16
- # Prepare the input dictionary
 
17
  inputs = {'text': full_prompt, 'duration': duration}
18
  if image:
19
- inputs['image'] = image # Include image if provided
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 - AI Pokémon Shorts Generator")
28
- gr.Markdown("Enter a prompt, choose a Pokémon style, adjust video duration, and (optionally) upload an image to generate a Pokémon-themed video!")
29
-
 
 
30
  with gr.Row():
31
- prompt = gr.Textbox(label="Enter Pokémon Scene", placeholder="Pikachu using Thunderbolt in a forest")
32
- style = gr.Dropdown(["Anime", "Classic Pokémon", "Modern 3D"], label="Pokémon Style", value="Anime")
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 = gr.Button("Generate Pokémon Video")
38
- output_video = gr.Video(label="Generated Pokémon Video")
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()