Jiangxz01 commited on
Commit
57d4798
·
verified ·
1 Parent(s): a6c9ed4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -180,23 +180,30 @@ async def tts_generate(input_text, speaker1, speaker2):
180
 
181
  async def process_podcast(input_text, language, speaker1, speaker2, api_key):
182
  podcast_script = generate_response(input_text, language, speaker1, speaker2, api_key)
 
 
 
 
 
 
 
 
 
 
183
  audio_file = await tts_generate(podcast_script, speaker1, speaker2)
184
- return podcast_script, audio_file
185
 
186
  custom_css = """
187
  body {
188
  background-color: #f0f8ff;
189
- margin: 0 !important;
190
  }
191
  .gradio-container {
192
  background-color: #f0f8ff;
193
  border-radius: 20px;
194
  box-shadow: 0 0 20px rgba(0,0,0,0.1);
195
- margin: 0 !important;
196
  }
197
  .center-aligned {
198
  text-align: center !important;
199
- margin: 0 !important;
200
  color: #ff4081;
201
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
202
  }
 
180
 
181
  async def process_podcast(input_text, language, speaker1, speaker2, api_key):
182
  podcast_script = generate_response(input_text, language, speaker1, speaker2, api_key)
183
+
184
+ try:
185
+ podcast_data = json.loads(podcast_script)
186
+ podcast_text = ""
187
+ for line in podcast_data.get("podcast", []):
188
+ speaker = f"speaker{line['speaker']}" if isinstance(line['speaker'], int) else line['speaker']
189
+ podcast_text += f"{speaker}:{line['line']}\n"
190
+ except json.JSONDecodeError:
191
+ podcast_text = "Error: Unable to parse the podcast script."
192
+
193
  audio_file = await tts_generate(podcast_script, speaker1, speaker2)
194
+ return podcast_text, audio_file
195
 
196
  custom_css = """
197
  body {
198
  background-color: #f0f8ff;
 
199
  }
200
  .gradio-container {
201
  background-color: #f0f8ff;
202
  border-radius: 20px;
203
  box-shadow: 0 0 20px rgba(0,0,0,0.1);
 
204
  }
205
  .center-aligned {
206
  text-align: center !important;
 
207
  color: #ff4081;
208
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
209
  }