orrinin commited on
Commit
a15d058
·
verified ·
1 Parent(s): 47c5cd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -72,9 +72,9 @@ rss_feed = 'https://www.scmp.com/rss/4/feed'
72
  apikey = os.environ.get("API_KEY")
73
  co = cohere.Client(api_key=apikey)
74
 
 
75
 
76
  # RSS feeds
77
-
78
  def is_url(string):
79
  url_pattern = re.compile(
80
  r'^(?:http|ftp)s?://' # http:// or https://
@@ -161,21 +161,17 @@ def extract_content(text):
161
  else:
162
  return None
163
 
164
- async def main(link, peoples="双人"):
 
165
  if not link.startswith("http://") and not link.startswith("https://"):
166
  return "URL must start with 'http://' or 'https://'",None
167
- system_prompt = ""
168
  text = fetch_text(link)
169
 
170
  if "Error" in text:
171
  return text, None
172
 
173
  prompt = f"Info: {text}"
174
-
175
- if peoples == "双人":
176
- system_prompt = double_prompt;
177
- else:
178
- system_prompt = single_prompt;
179
 
180
  messages = system_prompt + "\n\n\n" + prompt
181
 
@@ -231,6 +227,10 @@ with gr.Blocks(theme='soft', css=css, title="听说") as iface:
231
  input_box = gr.Textbox(label="网址", placeholder="请输入https开头的网址")
232
  with gr.Row():
233
  peoples = gr.Radio(["单人","双人"],value="双人",label="播音员人数")
 
 
 
 
234
  with gr.Row():
235
  submit_btn = gr.Button("🚀 发送") # Create a submit button
236
  random_btn = gr.Button("🤙 随机")
@@ -238,7 +238,7 @@ with gr.Blocks(theme='soft', css=css, title="听说") as iface:
238
  gr.Examples(examples=Examples, inputs=input_box, outputs=output_box, fn=main, label="示例", cache_examples="lazy")
239
 
240
  # Set up the event listeners
241
- submit_btn.click(main, inputs=[input_box, peoples], outputs=output_box)
242
  random_btn.click(fn=random_news, outputs=output_box)
243
 
244
 
 
72
  apikey = os.environ.get("API_KEY")
73
  co = cohere.Client(api_key=apikey)
74
 
75
+ system_prompt = ""
76
 
77
  # RSS feeds
 
78
  def is_url(string):
79
  url_pattern = re.compile(
80
  r'^(?:http|ftp)s?://' # http:// or https://
 
161
  else:
162
  return None
163
 
164
+ async def main(link):
165
+ global system_prompt
166
  if not link.startswith("http://") and not link.startswith("https://"):
167
  return "URL must start with 'http://' or 'https://'",None
168
+
169
  text = fetch_text(link)
170
 
171
  if "Error" in text:
172
  return text, None
173
 
174
  prompt = f"Info: {text}"
 
 
 
 
 
175
 
176
  messages = system_prompt + "\n\n\n" + prompt
177
 
 
227
  input_box = gr.Textbox(label="网址", placeholder="请输入https开头的网址")
228
  with gr.Row():
229
  peoples = gr.Radio(["单人","双人"],value="双人",label="播音员人数")
230
+ if peoples == "双人":
231
+ system_prompt = double_prompt;
232
+ else:
233
+ system_prompt = single_prompt;
234
  with gr.Row():
235
  submit_btn = gr.Button("🚀 发送") # Create a submit button
236
  random_btn = gr.Button("🤙 随机")
 
238
  gr.Examples(examples=Examples, inputs=input_box, outputs=output_box, fn=main, label="示例", cache_examples="lazy")
239
 
240
  # Set up the event listeners
241
+ submit_btn.click(main, inputs=input_box, outputs=output_box)
242
  random_btn.click(fn=random_news, outputs=output_box)
243
 
244