Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
link = f"https://huggingface.co/datasets/your-username/your-dataset/resolve/main/{file_name}"
|
| 15 |
|
| 16 |
-
# Call the video generator
|
| 17 |
-
|
|
|
|
| 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 |
+
|