MySafeCode commited on
Commit
c09f712
·
verified ·
1 Parent(s): 12488b1

Create app6.py

Browse files
Files changed (1) hide show
  1. app6.py +99 -0
app6.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import time
4
+ import logging
5
+ from byteplussdkarkruntime import Ark
6
+ import byteplussdkcore
7
+
8
+ # Set up logging
9
+ logging.basicConfig(level=logging.INFO)
10
+ logger = logging.getLogger(__name__)
11
+
12
+ # Get API key
13
+ API_KEY = os.environ.get("key", "")
14
+
15
+ # Configure SDK exactly as per the notice
16
+ configuration = byteplussdkcore.Configuration()
17
+ configuration.client_side_validation = True
18
+ configuration.schema = "http" # Explicitly set to HTTP as per notice
19
+ configuration.debug = False
20
+ configuration.logger_file = "sdk.log"
21
+ byteplussdkcore.Configuration.set_default(configuration)
22
+
23
+ # Initialize client
24
+ client = Ark(
25
+ base_url="https://ark.ap-southeast.bytepluses.com/api/v3",
26
+ api_key=API_KEY,
27
+ )
28
+
29
+ def generate_video(prompt_text, image_url):
30
+ """Generate video using properly configured SDK"""
31
+
32
+ try:
33
+ # Create task exactly like original code
34
+ create_result = client.content_generation.tasks.create(
35
+ model="seedance-1-5-pro-251215",
36
+ content=[
37
+ {
38
+ "type": "text",
39
+ "text": prompt_text
40
+ },
41
+ {
42
+ "type": "image_url",
43
+ "image_url": {
44
+ "url": image_url
45
+ }
46
+ }
47
+ ]
48
+ )
49
+
50
+ task_id = create_result.id
51
+ yield f"Task created: {task_id}", None
52
+
53
+ # Poll for results
54
+ while True:
55
+ get_result = client.content_generation.tasks.get(task_id=task_id)
56
+ status = get_result.status
57
+
58
+ if status == "succeeded":
59
+ video_url = get_result.output[0].get('video_url') if get_result.output else None
60
+ yield "Success!", video_url
61
+ break
62
+ elif status == "failed":
63
+ yield f"Failed: {get_result.error}", None
64
+ break
65
+ else:
66
+ yield f"Status: {status}...", None
67
+ time.sleep(1)
68
+
69
+ except Exception as e:
70
+ yield f"Error: {str(e)}", None
71
+
72
+ # Simple interface
73
+ with gr.Blocks() as demo:
74
+ gr.Markdown("# BytePlus Video Generator")
75
+
76
+ with gr.Row():
77
+ with gr.Column():
78
+ prompt = gr.Textbox(
79
+ label="Prompt",
80
+ lines=3,
81
+ value="At breakneck speed, drones fly through obstacles --duration 5 --camerafixed false"
82
+ )
83
+ image_url = gr.Textbox(
84
+ label="Image URL",
85
+ value="https://ark-doc.tos-ap-southeast-1.bytepluses.com/seepro_i2v%20.png"
86
+ )
87
+ btn = gr.Button("Generate", variant="primary")
88
+
89
+ with gr.Column():
90
+ status = gr.Textbox(label="Status")
91
+ video = gr.Video(label="Generated Video")
92
+
93
+ btn.click(
94
+ fn=generate_video,
95
+ inputs=[prompt, image_url],
96
+ outputs=[status, video]
97
+ )
98
+
99
+ demo.launch()