sherif1313 commited on
Commit
a4e44d5
·
verified ·
1 Parent(s): 6cbbce6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env python3
2
  from __future__ import annotations
3
 
4
  import os
@@ -39,6 +38,10 @@ FIXED_CHECKPOINT_REPO = "sherif1313/3arab-TTS-500M-v1-VoiceDesign"
39
 
40
  MAX_GRADIO_CANDIDATES = 32
41
  GRADIO_AUDIO_COLS_PER_ROW = 8
 
 
 
 
42
  # ===========================================================
43
 
44
  def _resolve_checkpoint_path() -> str:
@@ -226,6 +229,14 @@ def _run_generation(
226
  manual_seconds = _parse_optional_float(seconds_raw, "seconds")
227
  lora_adapter = _parse_optional_str(lora_adapter_raw)
228
 
 
 
 
 
 
 
 
 
229
  runtime, reloaded = get_cached_runtime(runtime_key)
230
  if not runtime.model_cfg.use_caption_condition:
231
  raise ValueError(
@@ -330,10 +341,10 @@ def build_ui() -> gr.Blocks:
330
 
331
  with gr.Accordion("Sampling", open=True):
332
  with gr.Row():
333
- num_steps = gr.Slider(label="Num Steps", minimum=1, maximum=120, value=16, step=1)
334
  num_candidates = gr.Slider(label="Num Candidates", minimum=1, maximum=MAX_GRADIO_CANDIDATES, value=1, step=1)
335
  seed_raw = gr.Textbox(label="Seed (blank=random)", value="")
336
- seconds_raw = gr.Textbox(label="Seconds (blank=auto)", value="")
337
  duration_scale = gr.Slider(label="Duration Scale", minimum=0.5, maximum=1.5, value=1.0, step=0.01)
338
 
339
  with gr.Row():
@@ -393,7 +404,7 @@ def build_ui() -> gr.Blocks:
393
  demo = build_ui()
394
  demo.queue(default_concurrency_limit=1)
395
  demo.launch(
396
- server_name="0.0.0.0", # ضروري جداً لكي يعمل على HF Spaces
397
- server_port=7860, # المنفذ الافتراضي المطلوب من HF
398
- share=False # يجب أن يكون False دائماً في HF Spaces
399
  )
 
 
1
  from __future__ import annotations
2
 
3
  import os
 
38
 
39
  MAX_GRADIO_CANDIDATES = 32
40
  GRADIO_AUDIO_COLS_PER_ROW = 8
41
+
42
+ # معامل سرعة النطق (عدد الحروف في الثانية الواحدة)
43
+ AVG_CHARS_PER_SEC = 6.0
44
+ MAX_AUTO_SECONDS = 30.0
45
  # ===========================================================
46
 
47
  def _resolve_checkpoint_path() -> str:
 
229
  manual_seconds = _parse_optional_float(seconds_raw, "seconds")
230
  lora_adapter = _parse_optional_str(lora_adapter_raw)
231
 
232
+ # ================== التعديل الجديد: حساب المدة تلقائياً من طول النص ==================
233
+ if manual_seconds is None:
234
+ # تقدير المدة بناءً على عدد الحروف (متوسط 6 حروف/ثانية)
235
+ estimated_seconds = max(1.0, len(text_value) / AVG_CHARS_PER_SEC)
236
+ manual_seconds = min(estimated_seconds, MAX_AUTO_SECONDS)
237
+ print(f"[INFO] Auto‑estimated duration = {manual_seconds:.2f} s for text length {len(text_value)} chars.")
238
+ # ===================================================================================
239
+
240
  runtime, reloaded = get_cached_runtime(runtime_key)
241
  if not runtime.model_cfg.use_caption_condition:
242
  raise ValueError(
 
341
 
342
  with gr.Accordion("Sampling", open=True):
343
  with gr.Row():
344
+ num_steps = gr.Slider(label="Num Steps", minimum=1, maximum=120, value=40, step=1)
345
  num_candidates = gr.Slider(label="Num Candidates", minimum=1, maximum=MAX_GRADIO_CANDIDATES, value=1, step=1)
346
  seed_raw = gr.Textbox(label="Seed (blank=random)", value="")
347
+ seconds_raw = gr.Textbox(label="Seconds (blank=auto from text length)", value="") # تم تغيير التلميحة
348
  duration_scale = gr.Slider(label="Duration Scale", minimum=0.5, maximum=1.5, value=1.0, step=0.01)
349
 
350
  with gr.Row():
 
404
  demo = build_ui()
405
  demo.queue(default_concurrency_limit=1)
406
  demo.launch(
407
+ server_name="0.0.0.0",
408
+ server_port=7860,
409
+ share=False
410
  )