theQuert commited on
Commit
eef0261
1 Parent(s): 72e6cd6

Update interfaces and add examples

Browse files
Files changed (1) hide show
  1. app.py +66 -1
app.py CHANGED
@@ -121,7 +121,8 @@ def config():
121
  load_dotenv()
122
 
123
  def call_gpt(paragraph, trigger):
124
- openai.api_key = os.environ.get("GPT_API")
 
125
  tokenizer = BartTokenizer.from_pretrained("theQuert/NetKUp-tokenzier")
126
  inputs_for_gpt = f"""
127
  As an article writer, your task is to provide an updated paragraph in the length same as non-updated paragraph based on the given non-updated paragraph and a triggered news.
@@ -270,6 +271,7 @@ def copy_to_clipboard(t):
270
  t = f.read()
271
  pyperclip.copy(t)
272
 
 
273
  demo = gr.Interface(
274
  main,
275
  [
@@ -296,5 +298,68 @@ demo = gr.Interface(
296
  title="Event Triggered Article Updating System",
297
  description="Powered by YTLee",
298
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
  demo.launch()
 
121
  load_dotenv()
122
 
123
  def call_gpt(paragraph, trigger):
124
+ # openai.api_key = os.environ.get("GPT_API")
125
+ openai.api_key = "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"
126
  tokenizer = BartTokenizer.from_pretrained("theQuert/NetKUp-tokenzier")
127
  inputs_for_gpt = f"""
128
  As an article writer, your task is to provide an updated paragraph in the length same as non-updated paragraph based on the given non-updated paragraph and a triggered news.
 
271
  t = f.read()
272
  pyperclip.copy(t)
273
 
274
+ """
275
  demo = gr.Interface(
276
  main,
277
  [
 
298
  title="Event Triggered Article Updating System",
299
  description="Powered by YTLee",
300
  )
301
+ """
302
+
303
+ with open("./examples/non_update.txt", "r") as f:
304
+ exin_1 = f.read()
305
+ with open("./examples/trigger.txt", "r") as f:
306
+ trigger_1 = f.read()
307
+ with open("./examples/non_update_2.txt", "r") as f:
308
+ exin_2 = f.read()
309
+ with open("./examples/trigger_2.txt", "r") as f:
310
+ trigger_2 = f.read()
311
+
312
+ with gr.Blocks() as demo:
313
+ gr.HTML("""<div style="text-align: center; max-width: 700px; margin: 0 auto;">
314
+ <div
315
+ style="
316
+ display: inline-flex;
317
+ align-items: center;
318
+ gap: 0.8rem;
319
+ font-size: 1.75rem;
320
+ "
321
+ >
322
+ <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
323
+ Event Triggered Article Updating System
324
+ </h1>
325
+ </div>"""
326
+ )
327
+ with gr.Tab("Article Updating"):
328
+ input_1 = gr.Textbox(label="Non-updated Article", lines=2, placeholder="Input the contexts...")
329
+ input_2 = gr.Textbox(label="Triggered News Event", lines=2, placeholder="Input the triggered news event...")
330
+ btn = gr.Button(value="Submit")
331
+ btn_copy = gr.Button(value="Copy to Clipboard")
332
+ with gr.Row():
333
+ output_1 = gr.Textbox(label="Updated Article", lines=10)
334
+ output_2 = gr.Textbox(label="#MODIFIED / #ALL")
335
+ btn.click(fn=main, inputs=[input_1, input_2], outputs=[output_1, output_2])
336
+ btn_copy.click(fn=copy_to_clipboard, inputs=[output_1], outputs=[])
337
+ gr.Markdown("## Input Examples")
338
+ gr.Examples(
339
+ examples=[[exin_1, trigger_1], [exin_2, trigger_2]],
340
+ fn=main,
341
+ inputs=[input_1, input_2],
342
+ outputs=[output_1, output_2],
343
+ # cache_examples=True
344
+ ),
345
+ with gr.Tab("Compare between versions"):
346
+ btn_com = gr.Button(value="Differnces highlighting")
347
+ btn_com.click(fn=copy_to_clipboard, inputs=[output_1], outputs=[])
348
+ with gr.Row():
349
+ com_1 = gr.Textbox(label="Non-update Article", lines=25)
350
+ com_2 = gr.Textbox(label="Updated Article", lines=25)
351
+ gr.HTML("""
352
+ <div align="center">
353
+ <p>
354
+ Demo by 🤗 <a href="https://github.com/thequert" target="_blank"><b>Yu-Ting Lee</b></a>
355
+ </p>
356
+ </div>
357
+ <div align="center">
358
+ <p>
359
+ Supported by <a href="https://www.nccu.edu.tw/"><b>National Chengchi University</a></b> & <a href="https://www.sinica.edu.tw/"><b>Academia Sinica</b></a>
360
+ </p>
361
+ </div>
362
+ """
363
+ )
364
 
365
  demo.launch()