Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ def generate_response(input_text, language, speaker1, speaker2, api_key):
|
|
| 19 |
language_instruction = "- The podcast MUST be in the same language as the user input."
|
| 20 |
else:
|
| 21 |
language_instruction = f"- The podcast Must reply to me in {language} language."
|
| 22 |
-
|
| 23 |
system_prompt = f"""你的任務是將提供的輸入文字轉換為一個引人入勝、訊息豐富且專業的Podcast對話。輸入文字可能會比較混亂或結構不完整,因為它可能來自不同來源,如PDF檔案或文字檔等。不要擔心格式問題或任何不相關的訊息;你的目標是提取可以在Podcast中討論的關鍵點、識別重要定義,並突出有趣的事實。
|
| 24 |
|
| 25 |
以下是你將要處理的輸入文字:
|
|
@@ -74,6 +74,16 @@ Follow this example structure, MUST be in {language} language:
|
|
| 74 |
],
|
| 75 |
temperature=1
|
| 76 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return response.choices[0].message.content
|
| 78 |
|
| 79 |
with gr.Blocks() as iface:
|
|
|
|
| 19 |
language_instruction = "- The podcast MUST be in the same language as the user input."
|
| 20 |
else:
|
| 21 |
language_instruction = f"- The podcast Must reply to me in {language} language."
|
| 22 |
+
|
| 23 |
system_prompt = f"""你的任務是將提供的輸入文字轉換為一個引人入勝、訊息豐富且專業的Podcast對話。輸入文字可能會比較混亂或結構不完整,因為它可能來自不同來源,如PDF檔案或文字檔等。不要擔心格式問題或任何不相關的訊息;你的目標是提取可以在Podcast中討論的關鍵點、識別重要定義,並突出有趣的事實。
|
| 24 |
|
| 25 |
以下是你將要處理的輸入文字:
|
|
|
|
| 74 |
],
|
| 75 |
temperature=1
|
| 76 |
)
|
| 77 |
+
try:
|
| 78 |
+
podcast_match = re.search(r'{(.*?)}', response.choices[0].message.content, re.DOTALL)
|
| 79 |
+
print(podcast_match)
|
| 80 |
+
except Exception as e:
|
| 81 |
+
if "API key not valid" in str(e):
|
| 82 |
+
raise gr.Error("Invalid API key. Please provide a valid API key.")
|
| 83 |
+
elif "rate limit" in str(e).lower():
|
| 84 |
+
raise gr.Error("Rate limit exceeded for the API key. Please try again later or provide your own API key.")
|
| 85 |
+
else:
|
| 86 |
+
raise gr.Error(f"Failed to generate podcast script: {e}")
|
| 87 |
return response.choices[0].message.content
|
| 88 |
|
| 89 |
with gr.Blocks() as iface:
|