Starlucas0201 commited on
Commit
afd5cda
·
verified ·
1 Parent(s): 72ccb2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,28 +1,31 @@
 
1
  import gradio as gr
2
  from script import generate_post_and_prompt, generate_video
3
 
4
  def run_pipeline(artist_name, image, num_frames):
5
- # Save uploaded image temporarily
6
- image_path = image.name
7
- file_name = image.name.split("/")[-1]
8
 
9
- # Generate Rednote post and video prompt
10
- post_text, prompt = generate_post_and_prompt(artist_name)
 
11
 
12
- # Assume the image is already uploaded to Hugging Face dataset with this filename
13
- # (Or you can modify this to upload programmatically)
14
- link = f"https://huggingface.co/datasets/your-username/your-dataset/resolve/main/{file_name}"
15
 
16
- # Call the video generator
17
- result = generate_video(prompt, num_frames, link)
 
18
 
 
19
  return post_text, result[0]["video"], result[1]
20
 
21
  iface = gr.Interface(
22
  fn=run_pipeline,
23
  inputs=[
24
  gr.Textbox(label="Artist Name"),
25
- gr.Image(type="filepath", label="Face Image"),
26
  gr.Slider(minimum=10, maximum=60, value=20, step=1, label="Number of Frames")
27
  ],
28
  outputs=[
@@ -30,8 +33,9 @@ iface = gr.Interface(
30
  gr.Video(label="Generated Video"),
31
  gr.Image(label="Thumbnail")
32
  ],
33
- title="Music Artist Video Generator",
34
  description="Upload an artist image and name to generate a video and Xiaohongshu-style post."
35
  )
36
 
37
  iface.launch()
 
 
1
+ import os
2
  import gradio as gr
3
  from script import generate_post_and_prompt, generate_video
4
 
5
  def run_pipeline(artist_name, image, num_frames):
6
+ # 1. Guard-rail: make sure user really uploaded something
7
+ if image is None:
8
+ return "❗Please upload a face image.", None, None
9
 
10
+ # 2. `image` is a filepath string → get its name
11
+ file_path = image # e.g. "/tmp/gradio/23abc/image.png"
12
+ file_name = os.path.basename(file_path) # "image.png"
13
 
14
+ # 3. GPT-4o: post + video prompt
15
+ post_text, prompt = generate_post_and_prompt(artist_name)
 
16
 
17
+ # 4. Call the video generator – `handle_file()` in script.py
18
+ # accepts either a local path or a URL, so pass `file_path`
19
+ result = generate_video(prompt, num_frames, link=file_path)
20
 
21
+ # 5. Return outputs to Gradio
22
  return post_text, result[0]["video"], result[1]
23
 
24
  iface = gr.Interface(
25
  fn=run_pipeline,
26
  inputs=[
27
  gr.Textbox(label="Artist Name"),
28
+ gr.Image(type="filepath", label="Face Image"), # <- keep `filepath`
29
  gr.Slider(minimum=10, maximum=60, value=20, step=1, label="Number of Frames")
30
  ],
31
  outputs=[
 
33
  gr.Video(label="Generated Video"),
34
  gr.Image(label="Thumbnail")
35
  ],
36
+ title="🎬 Music Artist Video Generator",
37
  description="Upload an artist image and name to generate a video and Xiaohongshu-style post."
38
  )
39
 
40
  iface.launch()
41
+