Pijush2023 commited on
Commit
c526396
·
verified ·
1 Parent(s): 8dc02c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -67,7 +67,7 @@ def fetch_local_events():
67
  api_key = os.environ['SERP_API']
68
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'
69
  response = requests.get(url)
70
- if response.status_code == 200:
71
  events_results = response.json().get("events_results", [])
72
  events_html = """
73
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
@@ -324,7 +324,7 @@ def fetch_local_news():
324
  api_key = os.environ['SERP_API']
325
  url = f'https://serpapi.com/search.json?engine=google_news&q=birmingham headline&api_key={api_key}'
326
  response = requests.get(url)
327
- if response.status_code == 200:
328
  results = response.json().get("news_results", [])
329
  news_html = """
330
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Birmingham Today</h2>
@@ -547,16 +547,6 @@ def generate_audio_parler_tts(text):
547
 
548
  # Load the MARS5 model
549
  mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)
550
- asr_model = pipeline(
551
- "automatic-speech-recognition",
552
- model="openai/whisper-tiny",
553
- chunk_length_s=30,
554
- device=torch.device("cuda:0"),
555
- )
556
-
557
- def transcribe_file(f: str) -> str:
558
- predictions = asr_model(f, return_timestamps=True)["chunks"]
559
- return " ".join([prediction["text"] for prediction in predictions])
560
 
561
  def generate_audio_mars5(text):
562
  description = "Thomas speaks with emphasis and excitement at a moderate pace with high quality."
@@ -575,12 +565,11 @@ def generate_audio_mars5(text):
575
 
576
  chunks = chunk_text(preprocess(text))
577
  audio_segments = []
 
578
  for chunk in chunks:
579
- transcript = transcribe_file(audio_path) # Assuming audio_path is the path to the audio file for reference
580
- wav, sr = librosa.load(audio_path, sr=mars5.sr, mono=True)
581
- wav = torch.from_numpy(wav)
582
  cfg = config_class(**kwargs_dict)
583
- ar_codes, wav_out = mars5.tts(chunk, wav, transcript.strip(), cfg=cfg)
584
 
585
  temp_audio_path = os.path.join(tempfile.gettempdir(), f"mars5_audio_{len(audio_segments)}.wav")
586
  torchaudio.save(temp_audio_path, wav_out.unsqueeze(0), mars5.sr)
@@ -651,6 +640,7 @@ demo.launch(share=True)
651
 
652
 
653
 
 
654
  # import gradio as gr
655
  # import requests
656
  # import os
 
67
  api_key = os.environ['SERP_API']
68
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'
69
  response = requests.get(url)
70
+ if response.status_code == 200):
71
  events_results = response.json().get("events_results", [])
72
  events_html = """
73
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
 
324
  api_key = os.environ['SERP_API']
325
  url = f'https://serpapi.com/search.json?engine=google_news&q=birmingham headline&api_key={api_key}'
326
  response = requests.get(url)
327
+ if response.status_code == 200):
328
  results = response.json().get("news_results", [])
329
  news_html = """
330
  <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Birmingham Today</h2>
 
547
 
548
  # Load the MARS5 model
549
  mars5, config_class = torch.hub.load('Camb-ai/mars5-tts', 'mars5_english', trust_repo=True)
 
 
 
 
 
 
 
 
 
 
550
 
551
  def generate_audio_mars5(text):
552
  description = "Thomas speaks with emphasis and excitement at a moderate pace with high quality."
 
565
 
566
  chunks = chunk_text(preprocess(text))
567
  audio_segments = []
568
+
569
  for chunk in chunks:
570
+ wav = torch.zeros(1, mars5.sr) # Use a placeholder silent audio for the reference
 
 
571
  cfg = config_class(**kwargs_dict)
572
+ ar_codes, wav_out = mars5.tts(chunk, wav, "", cfg=cfg)
573
 
574
  temp_audio_path = os.path.join(tempfile.gettempdir(), f"mars5_audio_{len(audio_segments)}.wav")
575
  torchaudio.save(temp_audio_path, wav_out.unsqueeze(0), mars5.sr)
 
640
 
641
 
642
 
643
+
644
  # import gradio as gr
645
  # import requests
646
  # import os