File size: 1,774 Bytes
3d274c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import os
import tempfile
import base64
from main import process
def process_image_and_generate_video(image, prompt):
# Create a temporary directory for intermediate files
with tempfile.TemporaryDirectory() as temp_dir:
# Save the uploaded image to a temporary file
temp_image_path = os.path.join(temp_dir, "input_image.png")
image.save(temp_image_path)
# Encode the image as base64 and create a data URL
with open(temp_image_path, "rb") as f:
encoded_image = base64.b64encode(f.read()).decode("utf-8")
data_url = f"data:image/png;base64,{encoded_image}"
# Process the image and generate video
# The process function now handles saving to numbered directories
result, generated_image_path, video_path = process(data_url, prompt, temp_dir)
if result and video_path:
return video_path
else:
return None
# Create the Gradio interface
with gr.Blocks(title="Character Video Generation") as demo:
gr.Markdown("# Character Video Generation")
gr.Markdown("""
* Upload a high-quality image of a person
* Enter a prompt to generate a video
""")
with gr.Row():
with gr.Column():
input_image = gr.Image(type="pil", label="Upload Reference Image")
prompt = gr.Textbox(label="Enter your prompt")
generate_btn = gr.Button("Generate")
with gr.Column():
output_video = gr.Video(label="Generated Video")
generate_btn.click(
fn=process_image_and_generate_video,
inputs=[input_image, prompt],
outputs=[output_video]
)
if __name__ == "__main__":
demo.launch(share=True)
|