| | import gradio as gr |
| | import requests |
| | import os |
| | import time |
| | import json |
| |
|
| | |
| | API_KEY = os.environ.get("Key", "") |
| |
|
| | def generate_video(prompt_text, image_url): |
| | """Exactly like the curl command""" |
| | |
| | |
| | create_url = "https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks" |
| | |
| | headers = { |
| | "Content-Type": "application/json", |
| | "Authorization": f"Bearer {API_KEY}" |
| | } |
| | |
| | |
| | data = { |
| | "model": "seedance-1-5-pro-251215", |
| | "content": [ |
| | { |
| | "type": "text", |
| | "text": prompt_text |
| | }, |
| | { |
| | "type": "image_url", |
| | "image_url": { |
| | "url": image_url |
| | } |
| | } |
| | ] |
| | } |
| | |
| | |
| | response = requests.post(create_url, headers=headers, json=data) |
| | |
| | if response.status_code != 200: |
| | return f"Error: {response.text}", None |
| | |
| | task_id = response.json()["id"] |
| | |
| | |
| | status_url = f"https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks/{task_id}" |
| | |
| | for _ in range(60): |
| | status_response = requests.get(status_url, headers=headers) |
| | result = status_response.json() |
| | |
| | if result.get("status") == "succeeded": |
| | |
| | video_url = result.get("output", [{}])[0].get("video_url") |
| | return "Success!", video_url |
| | elif result.get("status") == "failed": |
| | return f"Failed: {result.get('error')}", None |
| | |
| | time.sleep(1) |
| | |
| | return "Timeout", None |
| |
|
| | |
| | with gr.Blocks() as demo: |
| | gr.Markdown("# BytePlus Video Generator") |
| | gr.Markdown(f"API Key loaded: {'✅' if API_KEY else '❌'}") |
| | |
| | with gr.Row(): |
| | with gr.Column(): |
| | prompt = gr.Textbox( |
| | label="Prompt", |
| | lines=3, |
| | value="At breakneck speed, drones fly through obstacles --duration 5 --camerafixed false" |
| | ) |
| | image_url = gr.Textbox( |
| | label="Image URL", |
| | value="https://ark-doc.tos-ap-southeast-1.bytepluses.com/seepro_i2v%20.png" |
| | ) |
| | btn = gr.Button("Generate", variant="primary") |
| | |
| | with gr.Column(): |
| | status = gr.Textbox(label="Status") |
| | video = gr.Video(label="Result") |
| | |
| | btn.click( |
| | fn=generate_video, |
| | inputs=[prompt, image_url], |
| | outputs=[status, video] |
| | ) |
| |
|
| | demo.launch() |