yonagush commited on
Commit
be0bbc1
Β·
verified Β·
1 Parent(s): e365004

fix: lazy-load trafilatura+edge_tts, unbuffered stdout, disable gradio analytics

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -13,6 +13,10 @@ Features
13
  add news lower-third, ticker, channel logo β€” instant news-style reel
14
  """
15
 
 
 
 
 
16
  # ── stdlib ────────────────────────────────────────────────────────────────────
17
  import asyncio
18
  import os
@@ -27,10 +31,9 @@ import gradio as gr
27
  import numpy as np
28
  import requests
29
  import soundfile as sf
30
- import trafilatura
31
- import edge_tts
32
  from groq import Groq
33
  from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance
 
34
 
35
  # ─────────────────────────────────────────────────────────────────────────────
36
  # CONSTANTS
@@ -194,6 +197,7 @@ def get_font(size: int = 72, bold: bool = True) -> ImageFont.FreeTypeFont:
194
  # URL SCRAPING
195
  # ─────────────────────────────────────────────────────────────────────────────
196
  def scrape_url(url: str) -> str:
 
197
  try:
198
  dl = trafilatura.fetch_url(url)
199
  text = trafilatura.extract(dl, include_tables=False, include_comments=False, favor_recall=True)
@@ -232,6 +236,7 @@ def generate_script(
232
  # AUDIO β€” Edge TTS
233
  # ─────────────────────────────────────────────────────────────────────────────
234
  async def _edge_save(text: str, voice: str, path: str) -> None:
 
235
  await edge_tts.Communicate(text, voice).save(path)
236
 
237
  def generate_audio_edge(text: str, voice_display: str) -> str:
@@ -906,4 +911,6 @@ with gr.Blocks(title="🎬 AI Reels Maker", css=CSS, theme=gr.themes.Soft()) as
906
  | **Pexels** *(optional)* | Free HD stock video backgrounds | [pexels.com/api](https://www.pexels.com/api/) |
907
  """)
908
 
 
 
909
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
13
  add news lower-third, ticker, channel logo β€” instant news-style reel
14
  """
15
 
16
+ # ── unbuffered stdout so container logs appear in real-time ──────────────────
17
+ import sys
18
+ sys.stdout.reconfigure(line_buffering=True)
19
+
20
  # ── stdlib ────────────────────────────────────────────────────────────────────
21
  import asyncio
22
  import os
 
31
  import numpy as np
32
  import requests
33
  import soundfile as sf
 
 
34
  from groq import Groq
35
  from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance
36
+ print("βœ“ all top-level imports done", flush=True)
37
 
38
  # ─────────────────────────────────────────────────────────────────────────────
39
  # CONSTANTS
 
197
  # URL SCRAPING
198
  # ─────────────────────────────────────────────────────────────────────────────
199
  def scrape_url(url: str) -> str:
200
+ import trafilatura # lazy β€” avoid slow startup
201
  try:
202
  dl = trafilatura.fetch_url(url)
203
  text = trafilatura.extract(dl, include_tables=False, include_comments=False, favor_recall=True)
 
236
  # AUDIO β€” Edge TTS
237
  # ─────────────────────────────────────────────────────────────────────────────
238
  async def _edge_save(text: str, voice: str, path: str) -> None:
239
+ import edge_tts # lazy β€” avoid slow startup
240
  await edge_tts.Communicate(text, voice).save(path)
241
 
242
  def generate_audio_edge(text: str, voice_display: str) -> str:
 
911
  | **Pexels** *(optional)* | Free HD stock video backgrounds | [pexels.com/api](https://www.pexels.com/api/) |
912
  """)
913
 
914
+ os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False") # prevent analytics hang
915
+ print("βœ“ UI built, launching Gradio server…", flush=True)
916
  demo.launch(server_name="0.0.0.0", server_port=7860)