Shuja007's picture
Update app.py
5870b52 verified
raw
history blame
1.51 kB
import requests
import gradio as gr
import base64
# Function to call the NVIDIA API and generate a video
def generate_video(image):
# Convert the uploaded image to a base64 string
with open(image, "rb") as img_file:
image_base64 = base64.b64encode(img_file.read()).decode('utf-8')
invoke_url = "https://ai.api.nvidia.com/v1/genai/stabilityai/stable-video-diffusion"
headers = {
"Authorization": "Bearer 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",
"Accept": "application/json",
}
payload = {
"image": f"data:image/png;base64,{image_base64}",
"cfg_scale": 2.5,
"seed": 0
}
response = requests.post(invoke_url, headers=headers, json=payload)
response.raise_for_status()
response_body = response.json()
# Assuming the response contains a URL to the generated video
video_url = response_body.get('video_url')
return video_url
# Create a Gradio interface with a heading
def create_interface():
title = "Moving Product Shots"
# Gradio Interface
iface = gr.Interface(
fn=generate_video,
inputs=gr.Image(type="filepath", label="Upload Your Product Image"),
outputs=gr.Video(label="Generated Product Video"), # Use gr.Video to display the video output
title=title,
description="Upload a product shot to generate a moving video version of it."
)
iface.launch()
# Run the interface
create_interface()