Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,11 @@ import gradio as gr
|
|
5 |
import openai
|
6 |
import os
|
7 |
import re
|
8 |
-
import
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def create_client(api_key=None):
|
11 |
if api_key:
|
@@ -33,11 +37,8 @@ def generate_response(input_text, language, speaker1, speaker2, api_key):
|
|
33 |
|
34 |
<scratchpad>
|
35 |
頭腦風暴一些創造性的方法來討論你在輸入文字中識別出的主要話題、關鍵點及任何有趣的事實或軼事。可以考慮使用類比、講故事技巧或假設情境來讓內容對聽眾更加貼近和有趣。
|
36 |
-
|
37 |
請記住,你的Podcast應當易於普通聽眾理解,所以避免使用過多的專業術語或假設聽眾對該話題已有瞭解。如有必要,請思考如何用簡單的術語簡要解釋任何複雜的概念。
|
38 |
-
|
39 |
利用你的想像力填補輸入文字中的任何空白,或者想出一些值得探討與發人深省的問題,以供Podcast討論。目標是創造一個訊息豐富且娛樂性強的對話,因此可以在你的方法上大膽自由發揮創意。
|
40 |
-
|
41 |
將你的頭腦風暴想法和Podcast對話的粗略大綱寫在這裡。確保記錄下你希望在結尾重申的主要見解和要點。
|
42 |
</scratchpad>
|
43 |
|
@@ -50,20 +51,36 @@ def generate_response(input_text, language, speaker1, speaker2, api_key):
|
|
50 |
Follow this example structure, MUST be in {language} language:
|
51 |
```
|
52 |
{{
|
53 |
-
"
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}}
|
60 |
```
|
61 |
|
62 |
<podcast_dialogue>
|
63 |
根據你在頭腦風暴階段提出的關鍵點和創造性想法,撰寫你的引人入勝、訊息豐富的Podcast對話。採用對話式的語氣,並包括任何必要的上下文或解釋,使內容對一般聽眾而言容易理解。使用主持人名字 {speaker1_name} 和嘉賓名字 {speaker2_name},以營造更吸引人和身臨其境的聆聽體驗。不要包括像[主持人]或[嘉賓]這樣的括號預留位置。設計你的輸出內容以供直接朗讀——它將直接轉換為音訊。
|
64 |
-
|
65 |
確保對話儘可能詳細、完整,同時保持在主題之內並維持吸引人的流暢性。目標是使用你的全部輸出容量,建立儘可能長的Podcast節目,同時以有趣的方式傳遞輸入文字中的關鍵訊息。
|
66 |
-
|
67 |
在對話結束時,讓主持人和嘉賓自然總結他們討論中的主要見解和要點。這應當是對話的隨機部分,以自然隨意而非明顯的總結——目的是在結束前最後一次以自然流暢的方式強化核心思想。最終以感謝詞結束。
|
68 |
</podcast_dialogue>
|
69 |
"""
|
@@ -86,7 +103,7 @@ Follow this example structure, MUST be in {language} language:
|
|
86 |
raise gr.Error("Rate limit exceeded for the API key. Please try again later or provide your own API key.")
|
87 |
else:
|
88 |
raise gr.Error(f"Failed to generate podcast script: {e}")
|
89 |
-
return
|
90 |
|
91 |
with gr.Blocks() as iface:
|
92 |
gr.Markdown("# 🎙️ Generated Podcast Audio. Deployed by 江信宗")
|
@@ -129,10 +146,10 @@ with gr.Blocks() as iface:
|
|
129 |
)
|
130 |
|
131 |
api_key = gr.Textbox(label="API Key", type="password", placeholder="API authentication key for large language models")
|
132 |
-
|
133 |
|
134 |
generate_button = gr.Button("生成")
|
135 |
-
generate_button.click(fn=generate_response, inputs=[input_text, Language, Speaker_1, Speaker_2, api_key], outputs=
|
136 |
|
137 |
if __name__ == "__main__":
|
138 |
if "SPACE_ID" in os.environ:
|
|
|
5 |
import openai
|
6 |
import os
|
7 |
import re
|
8 |
+
import uuid
|
9 |
+
import io
|
10 |
+
import edge_tts
|
11 |
+
import asyncio
|
12 |
+
import aiofiles
|
13 |
|
14 |
def create_client(api_key=None):
|
15 |
if api_key:
|
|
|
37 |
|
38 |
<scratchpad>
|
39 |
頭腦風暴一些創造性的方法來討論你在輸入文字中識別出的主要話題、關鍵點及任何有趣的事實或軼事。可以考慮使用類比、講故事技巧或假設情境來讓內容對聽眾更加貼近和有趣。
|
|
|
40 |
請記住,你的Podcast應當易於普通聽眾理解,所以避免使用過多的專業術語或假設聽眾對該話題已有瞭解。如有必要,請思考如何用簡單的術語簡要解釋任何複雜的概念。
|
|
|
41 |
利用你的想像力填補輸入文字中的任何空白,或者想出一些值得探討與發人深省的問題,以供Podcast討論。目標是創造一個訊息豐富且娛樂性強的對話,因此可以在你的方法上大膽自由發揮創意。
|
|
|
42 |
將你的頭腦風暴想法和Podcast對話的粗略大綱寫在這裡。確保記錄下你希望在結尾重申的主要見解和要點。
|
43 |
</scratchpad>
|
44 |
|
|
|
51 |
Follow this example structure, MUST be in {language} language:
|
52 |
```
|
53 |
{{
|
54 |
+
"topic": "AGI",
|
55 |
+
"podcast": [
|
56 |
+
{
|
57 |
+
"speaker": 1,
|
58 |
+
"line": "Welcome to the 財資歐北共 Podcast. I am the host {speaker1_name}. Today we have invited an expert {speaker2_name} to join our program despite his busy schedule."
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"speaker": 2,
|
62 |
+
"line": "Hello everyone, I am {speaker2_name}, I am honored to come and chat with you."
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"speaker": 1,
|
66 |
+
"line": "Today we will discuss a very interesting topic..."
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"speaker": 2,
|
70 |
+
"line": "Yes, this topic is indeed fascinating. Let's start with..."
|
71 |
+
},
|
72 |
+
…………,
|
73 |
+
{
|
74 |
+
"speaker": 1,
|
75 |
+
"line": "Thank you {speaker2_name} for your professional sharing. Welcome to subscribe to the Wishing Podcast. Thank you and goodbye."
|
76 |
+
}
|
77 |
+
]
|
78 |
}}
|
79 |
```
|
80 |
|
81 |
<podcast_dialogue>
|
82 |
根據你在頭腦風暴階段提出的關鍵點和創造性想法,撰寫你的引人入勝、訊息豐富的Podcast對話。採用對話式的語氣,並包括任何必要的上下文或解釋,使內容對一般聽眾而言容易理解。使用主持人名字 {speaker1_name} 和嘉賓名字 {speaker2_name},以營造更吸引人和身臨其境的聆聽體驗。不要包括像[主持人]或[嘉賓]這樣的括號預留位置。設計你的輸出內容以供直接朗讀——它將直接轉換為音訊。
|
|
|
83 |
確保對話儘可能詳細、完整,同時保持在主題之內並維持吸引人的流暢性。目標是使用你的全部輸出容量,建立儘可能長的Podcast節目,同時以有趣的方式傳遞輸入文字中的關鍵訊息。
|
|
|
84 |
在對話結束時,讓主持人和嘉賓自然總結他們討論中的主要見解和要點。這應當是對話的隨機部分,以自然隨意而非明顯的總結——目的是在結束前最後一次以自然流暢的方式強化核心思想。最終以感謝詞結束。
|
85 |
</podcast_dialogue>
|
86 |
"""
|
|
|
103 |
raise gr.Error("Rate limit exceeded for the API key. Please try again later or provide your own API key.")
|
104 |
else:
|
105 |
raise gr.Error(f"Failed to generate podcast script: {e}")
|
106 |
+
return podcast_match.group(0)
|
107 |
|
108 |
with gr.Blocks() as iface:
|
109 |
gr.Markdown("# 🎙️ Generated Podcast Audio. Deployed by 江信宗")
|
|
|
146 |
)
|
147 |
|
148 |
api_key = gr.Textbox(label="API Key", type="password", placeholder="API authentication key for large language models")
|
149 |
+
podcast_script = gr.Textbox(label="生成的結果")
|
150 |
|
151 |
generate_button = gr.Button("生成")
|
152 |
+
generate_button.click(fn=generate_response, inputs=[input_text, Language, Speaker_1, Speaker_2, api_key], outputs=podcast_script)
|
153 |
|
154 |
if __name__ == "__main__":
|
155 |
if "SPACE_ID" in os.environ:
|