Spaces:
Runtime error
Runtime error
# Gradio code example for image creation | |
import os | |
import io | |
import gradio as gr | |
from PIL import Image | |
import requests | |
#from gradio.mix import Series | |
irs_api_key = os.environ.get("IRS_API_KEY") | |
# Function to call the text-to-video model API | |
def text_to_video(prompt): | |
# Fetch the API key from the environment variable | |
api_key = os.environ.get("IRS_API_KEY") | |
url = "https://api-inference.huggingface.co/models/ali-vilab/text-to-video-ms-1.7b" | |
# Set up the headers for authentication | |
headers = { | |
"Authorization": f"Bearer {api_key}" | |
} | |
# Set up the payload with the input prompt | |
data = { | |
"prompt": prompt | |
} | |
# Make the request to the model API | |
response = requests.post(url, headers=headers, json=data) | |
# Check if the request was successful | |
if response.status_code == 200: | |
# Assuming the API returns the URL of the generated video | |
video_url = response.json().get("video_url") | |
return video_url | |
else: | |
# Handle errors or unsuccessful requests | |
return "Error generating video. Please try again." | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=text_to_video, | |
inputs=gr.Textbox(label="Enter your prompt"), | |
outputs=gr.Video(label="Generated Video"), | |
title="Text to Video Generation", | |
description="Enter a prompt to generate a video." | |
) | |
# Launch the Gradio app | |
if __name__ == "__main__": | |
iface.launch() | |