orrinin commited on
Commit
f0387da
·
verified ·
1 Parent(s): 435716b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -14,7 +14,7 @@ from groq import Groq
14
  from pydub import AudioSegment
15
  from moviepy.editor import AudioFileClip, concatenate_audioclips
16
 
17
- system_prompt = '''
18
  You are an insightful podcast generator. You have to create short conversations between Xiao and Yang that gives an overview of the News given by the user.
19
  Please provide the script and output strictly in the following JSON format:
20
  {
@@ -29,6 +29,21 @@ system_prompt = '''
29
  #Please note that the [string] you generate now must be in relaxed and natural Chinese.
30
  '''
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  DESCRIPTION = '''
33
  <div>
34
  <h1 style="text-align: center;">📻听说demo</h1>
@@ -148,10 +163,10 @@ def extract_content(text):
148
  else:
149
  return None
150
 
151
- async def main(link):
152
  if not link.startswith("http://") and not link.startswith("https://"):
153
  return "URL must start with 'http://' or 'https://'",None
154
-
155
  text = fetch_text(link)
156
 
157
  if "Error" in text:
@@ -159,6 +174,10 @@ async def main(link):
159
 
160
  prompt = f"News: {text}"
161
 
 
 
 
 
162
  messages = [
163
  {"role": "system", "content": system_prompt},
164
  {"role": "user", "content": prompt},
@@ -212,6 +231,8 @@ with gr.Blocks(theme='soft', css=css, title="听说") as iface:
212
  output_box = gr.Audio(label="播客", type="filepath", interactive=False, autoplay=True, elem_classes="audio") # Create an output textbox
213
  with gr.Row():
214
  input_box = gr.Textbox(label="网址", placeholder="请输入https开头的网址")
 
 
215
  with gr.Row():
216
  submit_btn = gr.Button("🚀 发送") # Create a submit button
217
  random_btn = gr.Button("🤙 随机")
@@ -219,7 +240,7 @@ with gr.Blocks(theme='soft', css=css, title="听说") as iface:
219
  gr.Examples(examples=Examples, inputs=input_box, outputs=output_box, fn=main, label="示例", cache_examples="lazy")
220
 
221
  # Set up the event listeners
222
- submit_btn.click(main, inputs=input_box, outputs=output_box)
223
  random_btn.click(fn=random_news, outputs=output_box)
224
 
225
 
 
14
  from pydub import AudioSegment
15
  from moviepy.editor import AudioFileClip, concatenate_audioclips
16
 
17
+ double_prompt = '''
18
  You are an insightful podcast generator. You have to create short conversations between Xiao and Yang that gives an overview of the News given by the user.
19
  Please provide the script and output strictly in the following JSON format:
20
  {
 
29
  #Please note that the [string] you generate now must be in relaxed and natural Chinese.
30
  '''
31
 
32
+ single_prompt = """
33
+ You are a podcast generator of sharp opinions and humor. You have to create short scripts for commentary on current events in the news given by the user.
34
+ Please provide the script and output strictly in the following JSON format:
35
+ {
36
+ "title": "[string]",
37
+ "content": {
38
+ "Yang_0: "[string]",
39
+ "Yang_0": "[string]",
40
+ ...
41
+ }
42
+ }
43
+ #Be concise. No less than five rounds of conversation.
44
+ #Please note that the [string] you generate now must be in relaxed and natural Chinese.
45
+ """
46
+
47
  DESCRIPTION = '''
48
  <div>
49
  <h1 style="text-align: center;">📻听说demo</h1>
 
163
  else:
164
  return None
165
 
166
+ async def main(link, peoples="双人"):
167
  if not link.startswith("http://") and not link.startswith("https://"):
168
  return "URL must start with 'http://' or 'https://'",None
169
+ system_prompt = ""
170
  text = fetch_text(link)
171
 
172
  if "Error" in text:
 
174
 
175
  prompt = f"News: {text}"
176
 
177
+ if peoples == "双人":
178
+ system_prompt = double_prompt;
179
+ else:
180
+ system_prompt = single_prompt;
181
  messages = [
182
  {"role": "system", "content": system_prompt},
183
  {"role": "user", "content": prompt},
 
231
  output_box = gr.Audio(label="播客", type="filepath", interactive=False, autoplay=True, elem_classes="audio") # Create an output textbox
232
  with gr.Row():
233
  input_box = gr.Textbox(label="网址", placeholder="请输入https开头的网址")
234
+ with gr.Row():
235
+ peoples = gr.CheckboxGrop(["单人","双人"],info="播音员人数")
236
  with gr.Row():
237
  submit_btn = gr.Button("🚀 发送") # Create a submit button
238
  random_btn = gr.Button("🤙 随机")
 
240
  gr.Examples(examples=Examples, inputs=input_box, outputs=output_box, fn=main, label="示例", cache_examples="lazy")
241
 
242
  # Set up the event listeners
243
+ submit_btn.click(main, inputs=[input_box, peoples], outputs=output_box)
244
  random_btn.click(fn=random_news, outputs=output_box)
245
 
246