Spaces:
Running
Running
Upload 2 files
Browse files- app.py +6 -4
- requirements.txt +1 -0
app.py
CHANGED
@@ -45,7 +45,7 @@ def create_client(api_key=None):
|
|
45 |
def generate_response(input_text, language, speaker1, speaker2, api_key):
|
46 |
speaker1_name = speaker1.split(' - ')[0]
|
47 |
speaker2_name = speaker2.split(' - ')[0]
|
48 |
-
gr.Info("正在生成 Podcast
|
49 |
start_time = time.time()
|
50 |
if language == "Auto Detect":
|
51 |
language_instruction = "- The podcast MUST be in the same language as the user input."
|
@@ -122,23 +122,25 @@ Follow this JSON example structure, MUST be in {language} language:
|
|
122 |
podcast_match = re.search(r'{.*}', response.choices[0].message.content, re.DOTALL)
|
123 |
if podcast_match:
|
124 |
podcast_json = podcast_match.group(0)
|
|
|
|
|
125 |
try:
|
126 |
json.loads(podcast_json)
|
127 |
except json.JSONDecodeError:
|
128 |
podcast_json = re.sub(r',\s*}', '}', podcast_json)
|
129 |
podcast_json = re.sub(r',\s*]', ']', podcast_json)
|
130 |
end_time = time.time()
|
131 |
-
gr.Info(f"已成功生成 Podcast
|
132 |
return podcast_json
|
133 |
else:
|
134 |
-
raise gr.Error("生成 Podcast
|
135 |
except Exception as e:
|
136 |
if "API key not valid" in str(e):
|
137 |
raise gr.Error("無效的 API 金鑰!!請提供有效的 API 金鑰。")
|
138 |
elif "rate limit" in str(e).lower():
|
139 |
raise gr.Error("API 金鑰使用額度已超過限制!!請稍後再試或使用其他 API 金鑰。")
|
140 |
else:
|
141 |
-
raise gr.Error(f"生成 Podcast
|
142 |
|
143 |
async def tts_generate(input_text, speaker1, speaker2):
|
144 |
voice_names = {
|
|
|
45 |
def generate_response(input_text, language, speaker1, speaker2, api_key):
|
46 |
speaker1_name = speaker1.split(' - ')[0]
|
47 |
speaker2_name = speaker2.split(' - ')[0]
|
48 |
+
gr.Info("正在生成 Podcast 劇本中......")
|
49 |
start_time = time.time()
|
50 |
if language == "Auto Detect":
|
51 |
language_instruction = "- The podcast MUST be in the same language as the user input."
|
|
|
122 |
podcast_match = re.search(r'{.*}', response.choices[0].message.content, re.DOTALL)
|
123 |
if podcast_match:
|
124 |
podcast_json = podcast_match.group(0)
|
125 |
+
if language == "繁體中文":
|
126 |
+
podcast_json = zhconv(podcast_json, "zh-tw")
|
127 |
try:
|
128 |
json.loads(podcast_json)
|
129 |
except json.JSONDecodeError:
|
130 |
podcast_json = re.sub(r',\s*}', '}', podcast_json)
|
131 |
podcast_json = re.sub(r',\s*]', ']', podcast_json)
|
132 |
end_time = time.time()
|
133 |
+
gr.Info(f"已成功生成 Podcast 劇本,執行時間: {(end_time - start_time):.2f} 秒。")
|
134 |
return podcast_json
|
135 |
else:
|
136 |
+
raise gr.Error("生成 Podcast 劇本失敗!!請稍後再試。")
|
137 |
except Exception as e:
|
138 |
if "API key not valid" in str(e):
|
139 |
raise gr.Error("無效的 API 金鑰!!請提供有效的 API 金鑰。")
|
140 |
elif "rate limit" in str(e).lower():
|
141 |
raise gr.Error("API 金鑰使用額度已超過限制!!請稍後再試或使用其他 API 金鑰。")
|
142 |
else:
|
143 |
+
raise gr.Error(f"生成 Podcast 劇本失敗!!請稍後再試。")
|
144 |
|
145 |
async def tts_generate(input_text, speaker1, speaker2):
|
146 |
voice_names = {
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ openai
|
|
3 |
pydub
|
4 |
edge-tts
|
5 |
aiofiles
|
|
|
6 |
pypdf
|
|
|
3 |
pydub
|
4 |
edge-tts
|
5 |
aiofiles
|
6 |
+
zhconv-rs
|
7 |
pypdf
|