orrinin commited on
Commit
402872c
·
verified ·
1 Parent(s): 99ea7e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -72,7 +72,7 @@ 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
- system_prompt = ""
76
 
77
  # RSS feeds
78
  def is_url(string):
@@ -161,8 +161,8 @@ def extract_content(text):
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
 
@@ -172,9 +172,13 @@ async def main(link):
172
  return text, None
173
 
174
  prompt = f"Info: {text}"
 
 
 
 
 
175
 
176
  messages = system_prompt + "\n\n\n" + prompt
177
-
178
 
179
  completion = co.chat(
180
  model="command-r",
@@ -200,7 +204,8 @@ async def main(link):
200
  return output_filename
201
 
202
 
203
- async def random_news():
 
204
  global rss_feed
205
  if not is_url(rss_feed):
206
  raise ValueError(f"{rss_feed} is not a valid RSS feed.")
@@ -234,13 +239,9 @@ with gr.Blocks(theme='soft', css=css, title="听说") as iface:
234
 
235
  gr.Examples(examples=Examples, inputs=input_box, outputs=output_box, fn=main, label="示例", cache_examples="lazy")
236
 
237
- if peoples == "双人":
238
- system_prompt = double_prompt
239
- else:
240
- system_prompt = single_prompt
241
  # Set up the event listeners
242
- submit_btn.click(main, inputs=input_box, outputs=output_box)
243
- random_btn.click(fn=random_news, outputs=output_box)
244
 
245
 
246
  #gr.close_all()
 
72
  apikey = os.environ.get("API_KEY")
73
  co = cohere.Client(api_key=apikey)
74
 
75
+ peoples = ""
76
 
77
  # RSS feeds
78
  def is_url(string):
 
161
  else:
162
  return None
163
 
164
+ async def main(link, peoples):
165
+ global peoples
166
  if not link.startswith("http://") and not link.startswith("https://"):
167
  return "URL must start with 'http://' or 'https://'",None
168
 
 
172
  return text, None
173
 
174
  prompt = f"Info: {text}"
175
+
176
+ if peoples == "双人":
177
+ system_prompt = double_prompt
178
+ else:
179
+ system_prompt = single_prompt
180
 
181
  messages = system_prompt + "\n\n\n" + prompt
 
182
 
183
  completion = co.chat(
184
  model="command-r",
 
204
  return output_filename
205
 
206
 
207
+ async def random_news(peoples):
208
+ global peoples
209
  global rss_feed
210
  if not is_url(rss_feed):
211
  raise ValueError(f"{rss_feed} is not a valid RSS feed.")
 
239
 
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, inputs=peoples, outputs=output_box)
245
 
246
 
247
  #gr.close_all()