Jaward commited on
Commit
e5ba644
·
verified ·
1 Parent(s): bd67bd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -31,9 +31,7 @@ logging.basicConfig(
31
  ]
32
  )
33
  logger = logging.getLogger(__name__)
34
- device = "cuda" if torch.cuda.is_available() else "cpu"
35
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
36
- logger.info("TTS model initialized on %s", device)
37
  # Set up environment
38
  if os.path.exists("/tmp"):
39
  OUTPUT_DIR = "/tmp/outputs" # Use /tmp for Huggingface Spaces
@@ -43,6 +41,15 @@ os.makedirs(OUTPUT_DIR, exist_ok=True)
43
  logger.info(f"Using output directory: {OUTPUT_DIR}")
44
  os.environ["COQUI_TOS_AGREED"] = "1"
45
 
 
 
 
 
 
 
 
 
 
46
  # Define Pydantic model for slide data
47
  class Slide(BaseModel):
48
  title: str
@@ -341,6 +348,16 @@ async def on_generate(api_service, api_key, serpapi_key, title, topic, instructi
341
  """
342
  return
343
 
 
 
 
 
 
 
 
 
 
 
344
  model_client = get_model_client(api_service, api_key)
345
 
346
  total_slides = num_slides # Use exactly the number of slides from input
@@ -861,7 +878,7 @@ with gr.Blocks(title="Agent Feynman") as demo:
861
  generate_btn = gr.Button("Generate Lecture")
862
  with gr.Column(scale=2):
863
  default_slide_html = """
864
- <div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; min-height: 700px; padding: 20px; text-align: center; border: 1px solid #ddd; border-radius: 8px;">
865
  <h2 style="font-style: italic; color: #555;">Waiting for lecture content...</h2>
866
  <p style="margin-top: 10px; font-size: 16px;">Please Generate lecture content via the form on the left first before lecture begins</p>
867
  </div>
 
31
  ]
32
  )
33
  logger = logging.getLogger(__name__)
34
+
 
 
35
  # Set up environment
36
  if os.path.exists("/tmp"):
37
  OUTPUT_DIR = "/tmp/outputs" # Use /tmp for Huggingface Spaces
 
41
  logger.info(f"Using output directory: {OUTPUT_DIR}")
42
  os.environ["COQUI_TOS_AGREED"] = "1"
43
 
44
+ # Initialize TTS model at the top
45
+ try:
46
+ device = "cuda" if torch.cuda.is_available() else "cpu"
47
+ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
48
+ logger.info("TTS model initialized on %s", device)
49
+ except Exception as e:
50
+ logger.error("Failed to initialize TTS model: %s", str(e))
51
+ tts = None
52
+
53
  # Define Pydantic model for slide data
54
  class Slide(BaseModel):
55
  title: str
 
348
  """
349
  return
350
 
351
+ if tts is None:
352
+ yield f"""
353
+ <div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; min-height: 700px; padding: 20px; text-align: center; border: 1px solid #ddd; border-radius: 8px;">
354
+ <h2 style="color: #d9534f;">TTS model initialization failed</h2>
355
+ <p style="margin-top: 20px;">The TTS model failed to initialize at startup.</p>
356
+ <p>Please ensure the Coqui TTS model is properly installed and try restarting the application.</p>
357
+ </div>
358
+ """
359
+ return
360
+
361
  model_client = get_model_client(api_service, api_key)
362
 
363
  total_slides = num_slides # Use exactly the number of slides from input
 
878
  generate_btn = gr.Button("Generate Lecture")
879
  with gr.Column(scale=2):
880
  default_slide_html = """
881
+ <div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; minISlide-height: 700px; padding: 20px; text-align: center; border: 1px solid #ddd; border-radius: 8px;">
882
  <h2 style="font-style: italic; color: #555;">Waiting for lecture content...</h2>
883
  <p style="margin-top: 10px; font-size: 16px;">Please Generate lecture content via the form on the left first before lecture begins</p>
884
  </div>