MySafeCode commited on
Commit
de660ca
·
verified ·
1 Parent(s): 2232aef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -23
app.py CHANGED
@@ -49,7 +49,7 @@ def initialize_sdk_config():
49
  def generate_video(input_api_key, prompt_text, image_url, model_id, progress=gr.Progress()):
50
  """Generate video using the BytePlus SDK"""
51
 
52
- # Use input API key if provided, otherwise fall back to environment variable
53
  effective_api_key = input_api_key if input_api_key and input_api_key != "key" else api_key
54
 
55
  if not effective_api_key:
@@ -171,7 +171,7 @@ custom_css = """
171
  """
172
 
173
  # Create Gradio interface
174
- with gr.Blocks(title="BytePlus Video Generator") as demo:
175
 
176
  gr.Markdown("""
177
  # 🎥 BytePlus Video Generator
@@ -180,7 +180,7 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
180
 
181
  # Show API key source
182
  if api_key:
183
- gr.Markdown("""
184
  <div class="env-badge">
185
  ✅ API Key loaded from environment variable 'Key'
186
  </div>
@@ -208,13 +208,8 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
208
  label="🔑 BytePlus API Key",
209
  placeholder="Enter your BytePlus API key here",
210
  type="password",
211
- value="key" if not api_key else "", # Empty if env var exists
212
- info=f"Using env var 'Key' by default. Enter only to override."
213
- )
214
-
215
- # Show if env var is being used
216
- env_status = gr.Markdown(
217
- f"*Using environment variable 'Key'*" if api_key else "*Enter API key above*"
218
  )
219
 
220
  # Model ID
@@ -248,7 +243,7 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
248
  )
249
 
250
  # Generate button
251
- generate_btn = gr.Button("🚀 Generate Video", variant="primary")
252
 
253
  with gr.Column(scale=1):
254
  # Status output
@@ -257,11 +252,10 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
257
  lines=5
258
  )
259
 
260
- # Video output
261
  video = gr.Video(
262
- label="🎬 Generated Video",
263
- show_download_button=True,
264
- show_share_button=True
265
  )
266
 
267
  # Video URL
@@ -269,15 +263,23 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
269
  label="🔗 Video URL",
270
  interactive=False
271
  )
 
 
 
 
 
 
 
 
272
 
273
  # Example prompts
274
  gr.Markdown("---")
275
  gr.Markdown("## 📋 Example Prompts")
276
 
277
  with gr.Row():
278
- example1 = gr.Button("🌄 Nature Drone")
279
- example2 = gr.Button("🏙️ City Racing")
280
- example3 = gr.Button("🌊 Ocean Waves")
281
 
282
  # Function to update image preview
283
  def update_preview(url):
@@ -290,7 +292,8 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
290
  img = Image.open(BytesIO(response.content))
291
  return img
292
  return None
293
- except:
 
294
  return None
295
 
296
  # Example prompt functions
@@ -303,6 +306,12 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
303
  def set_ocean():
304
  return "Drone following surfers riding massive waves, slow motion, dramatic ocean views, golden hour --duration 5 --camerafixed false"
305
 
 
 
 
 
 
 
306
  # Connect events
307
  image_url.change(
308
  fn=update_preview,
@@ -321,25 +330,30 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
321
  outputs=[status, video]
322
  )
323
 
324
- # Update video URL
325
  generate_event.then(
326
  fn=lambda url: url if url else "",
327
  inputs=[video],
328
  outputs=[video_url]
 
 
 
 
329
  )
330
 
331
  # Clear button
332
  clear_btn = gr.Button("🗑️ Clear", variant="secondary")
333
  clear_btn.click(
334
  fn=lambda: (
335
- "key" if not api_key else "", # Reset API key input
336
  "https://ark-doc.tos-ap-southeast-1.bytepluses.com/seepro_i2v%20.png",
337
  "Enter your prompt here...",
338
  "",
339
  None,
340
- ""
 
341
  ),
342
- outputs=[api_key_input, image_url, prompt, status, video, video_url]
343
  )
344
 
345
  # Footer
@@ -354,6 +368,7 @@ with gr.Blocks(title="BytePlus Video Generator") as demo:
354
  if __name__ == "__main__":
355
  demo.launch(
356
  server_name="0.0.0.0",
 
357
  theme=gr.themes.Soft(
358
  primary_hue="blue",
359
  secondary_hue="purple",
 
49
  def generate_video(input_api_key, prompt_text, image_url, model_id, progress=gr.Progress()):
50
  """Generate video using the BytePlus SDK"""
51
 
52
+ # Use input API key if provided and not "key", otherwise fall back to environment variable
53
  effective_api_key = input_api_key if input_api_key and input_api_key != "key" else api_key
54
 
55
  if not effective_api_key:
 
171
  """
172
 
173
  # Create Gradio interface
174
+ with gr.Blocks(title="BytePlus Video Generator", fill_width=True) as demo:
175
 
176
  gr.Markdown("""
177
  # 🎥 BytePlus Video Generator
 
180
 
181
  # Show API key source
182
  if api_key:
183
+ gr.Markdown(f"""
184
  <div class="env-badge">
185
  ✅ API Key loaded from environment variable 'Key'
186
  </div>
 
208
  label="🔑 BytePlus API Key",
209
  placeholder="Enter your BytePlus API key here",
210
  type="password",
211
+ value="" if api_key else "key", # Empty if env var exists, otherwise "key"
212
+ info="Using env var 'Key' by default. Enter only to override."
 
 
 
 
 
213
  )
214
 
215
  # Model ID
 
243
  )
244
 
245
  # Generate button
246
+ generate_btn = gr.Button("🚀 Generate Video", variant="primary", size="lg")
247
 
248
  with gr.Column(scale=1):
249
  # Status output
 
252
  lines=5
253
  )
254
 
255
+ # Video output - REMOVED the unsupported parameters
256
  video = gr.Video(
257
+ label="🎬 Generated Video"
258
+ # show_download_button and show_share_button removed as they're not in Gradio 6.5.1
 
259
  )
260
 
261
  # Video URL
 
263
  label="🔗 Video URL",
264
  interactive=False
265
  )
266
+
267
+ # Add download button separately if needed
268
+ with gr.Row():
269
+ download_btn = gr.DownloadButton(
270
+ label="📥 Download Video",
271
+ variant="secondary",
272
+ visible=False # Hidden until video is generated
273
+ )
274
 
275
  # Example prompts
276
  gr.Markdown("---")
277
  gr.Markdown("## 📋 Example Prompts")
278
 
279
  with gr.Row():
280
+ example1 = gr.Button("🌄 Nature Drone", size="sm")
281
+ example2 = gr.Button("🏙️ City Racing", size="sm")
282
+ example3 = gr.Button("🌊 Ocean Waves", size="sm")
283
 
284
  # Function to update image preview
285
  def update_preview(url):
 
292
  img = Image.open(BytesIO(response.content))
293
  return img
294
  return None
295
+ except Exception as e:
296
+ logger.error(f"Preview error: {e}")
297
  return None
298
 
299
  # Example prompt functions
 
306
  def set_ocean():
307
  return "Drone following surfers riding massive waves, slow motion, dramatic ocean views, golden hour --duration 5 --camerafixed false"
308
 
309
+ # Function to update download button when video is generated
310
+ def update_download_button(video_path):
311
+ if video_path and video_path != "None" and video_path != "":
312
+ return gr.update(visible=True, value=video_path)
313
+ return gr.update(visible=False)
314
+
315
  # Connect events
316
  image_url.change(
317
  fn=update_preview,
 
330
  outputs=[status, video]
331
  )
332
 
333
+ # Update video URL and download button
334
  generate_event.then(
335
  fn=lambda url: url if url else "",
336
  inputs=[video],
337
  outputs=[video_url]
338
+ ).then(
339
+ fn=update_download_button,
340
+ inputs=[video],
341
+ outputs=[download_btn]
342
  )
343
 
344
  # Clear button
345
  clear_btn = gr.Button("🗑️ Clear", variant="secondary")
346
  clear_btn.click(
347
  fn=lambda: (
348
+ "" if api_key else "key", # Reset API key input
349
  "https://ark-doc.tos-ap-southeast-1.bytepluses.com/seepro_i2v%20.png",
350
  "Enter your prompt here...",
351
  "",
352
  None,
353
+ "",
354
+ gr.update(visible=False)
355
  ),
356
+ outputs=[api_key_input, image_url, prompt, status, video, video_url, download_btn]
357
  )
358
 
359
  # Footer
 
368
  if __name__ == "__main__":
369
  demo.launch(
370
  server_name="0.0.0.0",
371
+ server_port=7860,
372
  theme=gr.themes.Soft(
373
  primary_hue="blue",
374
  secondary_hue="purple",