Update app.py
Browse files
app.py
CHANGED
|
@@ -119,16 +119,19 @@ async def main():
|
|
| 119 |
paragraphs_state = gr.State([""])
|
| 120 |
|
| 121 |
# 動態段落區塊
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
add_btn = gr.Button("新增段落")
|
| 127 |
remove_btn = gr.Button("刪除段落")
|
| 128 |
clear_all_btn = gr.Button("全部清空")
|
| 129 |
|
| 130 |
-
# 段落增減/清空時,重新渲染段落區塊
|
| 131 |
def update_paragraph_ui(paragraphs):
|
|
|
|
| 132 |
paragraph_column.children = render_paragraphs(paragraphs)
|
| 133 |
return gr.update()
|
| 134 |
|
|
@@ -159,7 +162,7 @@ async def main():
|
|
| 159 |
|
| 160 |
# 播客合成
|
| 161 |
def on_podcast_btn_click(*args):
|
| 162 |
-
n = len(
|
| 163 |
scripts = list(args[:n])
|
| 164 |
voice = args[n]
|
| 165 |
rate = args[n+1]
|
|
@@ -169,7 +172,7 @@ async def main():
|
|
| 169 |
desc = args[n+5]
|
| 170 |
return asyncio.run(podcast_produce(scripts, voice, rate, pitch, bgm, title, desc))
|
| 171 |
|
| 172 |
-
#
|
| 173 |
def get_inputs():
|
| 174 |
return [tb for tb in paragraph_column.children] + [voice_input2, rate_input2, pitch_input2, bgm_input, podcast_title, podcast_desc]
|
| 175 |
|
|
|
|
| 119 |
paragraphs_state = gr.State([""])
|
| 120 |
|
| 121 |
# 動態段落區塊
|
| 122 |
+
paragraph_column = gr.Column()
|
| 123 |
+
|
| 124 |
+
# 初始化
|
| 125 |
+
paragraph_boxes = render_paragraphs([""])
|
| 126 |
+
for tb in paragraph_boxes:
|
| 127 |
+
paragraph_column.append(tb)
|
| 128 |
|
| 129 |
add_btn = gr.Button("新增段落")
|
| 130 |
remove_btn = gr.Button("刪除段落")
|
| 131 |
clear_all_btn = gr.Button("全部清空")
|
| 132 |
|
|
|
|
| 133 |
def update_paragraph_ui(paragraphs):
|
| 134 |
+
# 重新渲染段落
|
| 135 |
paragraph_column.children = render_paragraphs(paragraphs)
|
| 136 |
return gr.update()
|
| 137 |
|
|
|
|
| 162 |
|
| 163 |
# 播客合成
|
| 164 |
def on_podcast_btn_click(*args):
|
| 165 |
+
n = len(paragraph_column.children)
|
| 166 |
scripts = list(args[:n])
|
| 167 |
voice = args[n]
|
| 168 |
rate = args[n+1]
|
|
|
|
| 172 |
desc = args[n+5]
|
| 173 |
return asyncio.run(podcast_produce(scripts, voice, rate, pitch, bgm, title, desc))
|
| 174 |
|
| 175 |
+
# 收集 paragraph_column.children 作為 inputs
|
| 176 |
def get_inputs():
|
| 177 |
return [tb for tb in paragraph_column.children] + [voice_input2, rate_input2, pitch_input2, bgm_input, podcast_title, podcast_desc]
|
| 178 |
|