yukee1992 commited on
Commit
2a5460d
·
verified ·
1 Parent(s): b0cab0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -12,7 +12,6 @@ from fastapi.middleware.cors import CORSMiddleware
12
  import uvicorn
13
  from huggingface_hub import HfApi, hf_hub_download
14
  from typing import Optional, List, Dict, Any
15
- import zipfile
16
 
17
  print("=" * 60)
18
  print("🚀 TEXT STYLING SPACE - WITH FONT DATASET")
@@ -238,12 +237,6 @@ def create_text_overlay(input_video, output_video, text_style):
238
 
239
  def add_subtitles(input_video, output_video, subtitle_style, tts_url=None):
240
  """Add subtitles to video"""
241
- # If we have TTS URL, generate subtitles first
242
- if tts_url:
243
- # This would use Whisper to generate SRT
244
- # For now, we'll use a placeholder
245
- pass
246
-
247
  # For now, just copy the video
248
  shutil.copy(input_video, output_video)
249
  return True
@@ -387,7 +380,7 @@ def create_gradio_interface():
387
  )
388
  title_font = gr.Dropdown(
389
  label="Font Family",
390
- choices=list(FONTS.keys()),
391
  value=list(FONTS.keys())[0] if FONTS else None
392
  )
393
  title_size = gr.Slider(24, 120, value=60, label="Font Size")
@@ -408,21 +401,13 @@ def create_gradio_interface():
408
  label="Position"
409
  )
410
 
411
- gr.Markdown("### Subtitles")
412
- subs_font = gr.Dropdown(
413
- label="Subtitle Font",
414
- choices=list(FONTS.keys()),
415
- value=list(FONTS.keys())[0] if FONTS else None
416
- )
417
- subs_size = gr.Slider(16, 60, value=32, label="Subtitle Size")
418
-
419
  style_btn = gr.Button("🎨 Style Video", variant="primary")
420
 
421
  with gr.Column(scale=1):
422
  output = gr.JSON(label="Result")
423
  styled_video = gr.Video(label="Styled Video Preview")
424
 
425
- def style_video_ui(pid, vid_url, title_txt, t_font, t_size, t_color, t_bg, t_opacity, t_pos, s_font, s_size):
426
  # Build request
427
  request = {
428
  "project_id": pid,
@@ -436,20 +421,13 @@ def create_gradio_interface():
436
  "position": t_pos,
437
  "margin": 20,
438
  "padding": 10
439
- } if title_txt else None,
440
- "subtitles": {
441
- "font_family": s_font,
442
- "font_size": s_size,
443
- "color": "white",
444
- "bg_color": "black@0.7",
445
- "position": "bottom"
446
- } if s_font else None
447
  }
448
 
449
  # Call API
450
  import requests
451
  response = requests.post(
452
- "https://yukee1992-text-styling.hf.space/api/style",
453
  json=request
454
  )
455
  return response.json(), response.json().get("styled_video_url")
@@ -458,8 +436,7 @@ def create_gradio_interface():
458
  fn=style_video_ui,
459
  inputs=[
460
  project_id, video_url, title_text, title_font, title_size,
461
- title_color, title_bg, title_opacity, title_position,
462
- subs_font, subs_size
463
  ],
464
  outputs=[output, styled_video]
465
  )
 
12
  import uvicorn
13
  from huggingface_hub import HfApi, hf_hub_download
14
  from typing import Optional, List, Dict, Any
 
15
 
16
  print("=" * 60)
17
  print("🚀 TEXT STYLING SPACE - WITH FONT DATASET")
 
237
 
238
  def add_subtitles(input_video, output_video, subtitle_style, tts_url=None):
239
  """Add subtitles to video"""
 
 
 
 
 
 
240
  # For now, just copy the video
241
  shutil.copy(input_video, output_video)
242
  return True
 
380
  )
381
  title_font = gr.Dropdown(
382
  label="Font Family",
383
+ choices=list(FONTS.keys()) if FONTS else [],
384
  value=list(FONTS.keys())[0] if FONTS else None
385
  )
386
  title_size = gr.Slider(24, 120, value=60, label="Font Size")
 
401
  label="Position"
402
  )
403
 
 
 
 
 
 
 
 
 
404
  style_btn = gr.Button("🎨 Style Video", variant="primary")
405
 
406
  with gr.Column(scale=1):
407
  output = gr.JSON(label="Result")
408
  styled_video = gr.Video(label="Styled Video Preview")
409
 
410
+ def style_video_ui(pid, vid_url, title_txt, t_font, t_size, t_color, t_bg, t_opacity, t_pos):
411
  # Build request
412
  request = {
413
  "project_id": pid,
 
421
  "position": t_pos,
422
  "margin": 20,
423
  "padding": 10
424
+ } if title_txt else None
 
 
 
 
 
 
 
425
  }
426
 
427
  # Call API
428
  import requests
429
  response = requests.post(
430
+ "http://localhost:7860/api/style",
431
  json=request
432
  )
433
  return response.json(), response.json().get("styled_video_url")
 
436
  fn=style_video_ui,
437
  inputs=[
438
  project_id, video_url, title_text, title_font, title_size,
439
+ title_color, title_bg, title_opacity, title_position
 
440
  ],
441
  outputs=[output, styled_video]
442
  )