MySafeCode commited on
Commit
a7673c2
·
verified ·
1 Parent(s): 8abfc99

Delete aa.py

Browse files
Files changed (1) hide show
  1. aa.py +0 -188
aa.py DELETED
@@ -1,188 +0,0 @@
1
- import os
2
- import time
3
- import gradio as gr
4
- import tempfile
5
- import requests
6
- from byteplussdkarkruntime import Ark
7
- from PIL import Image
8
- import io
9
-
10
- # Get API key from Hugging Face secret "Key"
11
- API_KEY = os.environ.get("Key", "")
12
-
13
- # Initialize client exactly like your working code
14
- client = Ark(
15
- base_url="https://ark.ap-southeast.bytepluses.com/api/v3",
16
- api_key=API_KEY,
17
- )
18
-
19
- def upload_image_to_temp_url(image):
20
- """Upload image to temporary hosting and return URL"""
21
- # For now, we need a public URL for the API
22
- # Option 1: Use a free image hosting service
23
- # Option 2: Save temporarily and return path (won't work for API)
24
- # Option 3: Keep URL input for now with preview
25
-
26
- # Let's keep it simple - return None and we'll handle it in the UI
27
- return None
28
-
29
- def generate_video(image, prompt_text, progress=gr.Progress()):
30
- """Generate video using your exact working code pattern"""
31
-
32
- if not API_KEY:
33
- yield "❌ API Key not configured. Please add 'Key' secret.", None
34
- return
35
-
36
- if image is None:
37
- yield "⚠️ Please upload an image first", None
38
- return
39
-
40
- try:
41
- progress(0, desc="Preparing image...")
42
-
43
- # Save uploaded image temporarily
44
- with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_file:
45
- image.save(tmp_file.name)
46
-
47
- # Upload to a temporary hosting service
48
- # For now, we'll use a placeholder - we need to implement this
49
- # Option: Use imgbb.com API or similar
50
- image_url = "https://ark-doc.tos-ap-southeast-1.bytepluses.com/seepro_i2v%20.png" # Placeholder
51
-
52
- # TODO: Implement actual image upload to hosting service
53
- yield "⏳ Note: Direct image upload needs hosting service. Using placeholder for now.", None
54
- time.sleep(1)
55
-
56
- progress(0.2, desc="Creating request...")
57
-
58
- # Exactly your working code structure
59
- print("----- create request -----")
60
- create_result = client.content_generation.tasks.create(
61
- model="seedance-1-5-pro-251215",
62
- content=[
63
- {
64
- "type": "text",
65
- "text": prompt_text
66
- },
67
- {
68
- "type": "image_url",
69
- "image_url": {
70
- "url": image_url
71
- }
72
- }
73
- ]
74
- )
75
-
76
- task_id = create_result.id
77
- print(f"Task created: {task_id}")
78
- yield f"✅ Task created: {task_id}", None
79
-
80
- progress(0.3, desc="Polling for results...")
81
-
82
- # Polling exactly like your working code
83
- attempts = 0
84
- max_attempts = 120 # 2 minutes max
85
-
86
- while attempts < max_attempts:
87
- get_result = client.content_generation.tasks.get(task_id=task_id)
88
- status = get_result.status
89
-
90
- if status == "succeeded":
91
- progress(1.0, desc="Complete!")
92
- # Extract video URL from the response structure we saw
93
- video_url = get_result.content.video_url if hasattr(get_result, 'content') else None
94
- print(f"Video URL: {video_url}")
95
- yield "✅ Video generated successfully!", video_url
96
- return
97
-
98
- elif status == "failed":
99
- error_msg = get_result.error if hasattr(get_result, 'error') else "Unknown error"
100
- yield f"❌ Failed: {error_msg}", None
101
- return
102
- else:
103
- progress(0.3 + (attempts/max_attempts)*0.7, desc=f"Status: {status}")
104
- yield f"⏳ Status: {status}... (attempt {attempts + 1})", None
105
- time.sleep(1)
106
- attempts += 1
107
-
108
- yield "⏰ Timeout after 2 minutes", None
109
-
110
- except Exception as e:
111
- print(f"Error: {e}")
112
- yield f"❌ Error: {str(e)}", None
113
-
114
- # Simple, clean interface
115
- with gr.Blocks(title="BytePlus Video Generator", theme=gr.themes.Soft()) as demo:
116
-
117
- gr.Markdown("""
118
- # 🎥 BytePlus Video Generator
119
-
120
- Upload an image and describe the video you want to generate.
121
- """)
122
-
123
- # Show API key status
124
- if API_KEY:
125
- gr.Markdown("✅ **API Key:** Configured")
126
- else:
127
- gr.Markdown("❌ **API Key:** Not configured - please add 'Key' secret")
128
-
129
- with gr.Row():
130
- with gr.Column():
131
- # Image upload
132
- image_input = gr.Image(
133
- label="Upload Starting Image",
134
- type="pil",
135
- height=300
136
- )
137
-
138
- # Text prompt
139
- prompt = gr.Textbox(
140
- label="Video Description",
141
- lines=4,
142
- placeholder="Describe what you want to see...",
143
- value="At breakneck speed, drones thread through intricate obstacles or stunning natural wonders, delivering an immersive, heart-pounding flying experience. --duration 5 --camerafixed false"
144
- )
145
-
146
- # Generate button
147
- generate_btn = gr.Button("🚀 Generate Video", variant="primary", size="lg")
148
-
149
- with gr.Column():
150
- # Status
151
- status = gr.Textbox(
152
- label="Status",
153
- lines=4,
154
- interactive=False
155
- )
156
-
157
- # Video output
158
- video_output = gr.Video(
159
- label="Generated Video",
160
- interactive=False
161
- )
162
-
163
- # Example prompts
164
- gr.Markdown("---")
165
- gr.Markdown("### Example Prompts")
166
- with gr.Row():
167
- gr.Button("Nature").click(
168
- fn=lambda: "Aerial drone shot over mountains at sunrise, cinematic --duration 5 --camerafixed false",
169
- outputs=prompt
170
- )
171
- gr.Button("City").click(
172
- fn=lambda: "Fast drone racing through futuristic city streets --duration 5 --camerafixed false",
173
- outputs=prompt
174
- )
175
- gr.Button("Ocean").click(
176
- fn=lambda: "Drone following waves at golden hour --duration 5 --camerafixed false",
177
- outputs=prompt
178
- )
179
-
180
- # Connect the generate button
181
- generate_event = generate_btn.click(
182
- fn=generate_video,
183
- inputs=[image_input, prompt],
184
- outputs=[status, video_output]
185
- )
186
-
187
- if __name__ == "__main__":
188
- demo.launch(server_name="0.0.0.0")