@@ -125,7 +125,7 @@ def config():
125
125
load_dotenv ()
126
126
127
127
def call_gpt (paragraph , trigger ):
128
- # openai.api_key = os.environ.get("GPT-API")
128
+ openai .api_key = os .environ .get ("GPT-API" )
129
129
tokenizer = BartTokenizer .from_pretrained ("theQuert/NetKUp-tokenzier" )
130
130
inputs_for_gpt = f"""
131
131
s 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.Remember, the length of updated paragraph is restricted into a single paragraph.
@@ -267,9 +267,30 @@ def main(input_article, input_trigger):
267
267
# merge updated paragraphs with non-updated paragraphs
268
268
paragraphs_merged = data_test .copy ()
269
269
paragraphs_merged = [str (par ).split (" -- " )[0 ] for par in paragraphs_merged ]
270
+ paragraphs_old = paragraphs_merged .copy ()
270
271
for idx in range (len (pos_ids )):
271
272
paragraphs_merged [pos_ids [idx ]] = updated_paragraphs [idx ]
272
-
273
+ global_pos = [pos_ids [idx ] for idx in range (len (pos_ids ))]
274
+
275
+ updated_color_sents = []
276
+ old_color_sents = []
277
+ for idx in range (len (paragraphs_merged )):
278
+ if idx not in global_pos :
279
+ # color_sents[paragraphs_merged]="white"
280
+ tup = (paragraphs_merged [idx ]+ "\n " , "Unchanged" )
281
+ updated_color_sents .append (tup )
282
+ else :
283
+ tup = (paragraphs_merged [idx ]+ "\n " , "Updated" )
284
+ updated_color_sents .append (tup )
285
+ for idx in range (len (paragraphs_old )):
286
+ if idx not in global_pos :
287
+ tup = (paragraphs_old [idx ]+ "\n " , "Unchanged" )
288
+ old_color_sents .append (tup )
289
+ else :
290
+ tup = (paragraphs_old [idx ]+ "\n " , "Modified" )
291
+ old_color_sents .append (tup )
292
+
293
+
273
294
sep = "\n "
274
295
# paragarphs_merged = ["".join(par.split(" -- ")[:-1]) for par in paragraphs_merged]
275
296
updated_article = str (sep .join (paragraphs_merged ))
@@ -285,9 +306,10 @@ def main(input_article, input_trigger):
285
306
286
307
# combine the predictions and paragraphs into csv format file
287
308
merged_par_pred_df = pd .DataFrame ({"paragraphs" : data_test , "predictions" : predictions }).to_csv ("./util/experiments/par_with_class.csv" )
288
- # return updated_article, modified, merged_par_pred_df
289
- modified_in_all = str (len (paragraphs_needed )) + " / " + str (len (data_test ))
290
- return updated_article , modified_in_all
309
+ # modified_in_all = str(len(paragraphs_needed)) + " / " + str(len(data_test))
310
+ # return formatted_input, updated_article
311
+ # return formatted_input, updated_color_sents
312
+ return old_color_sents , updated_color_sents
291
313
292
314
def copy_to_clipboard (t ):
293
315
with open ("./util/experiments/updated_article.txt" , "r" ) as f :
@@ -328,17 +350,32 @@ def compare_versions():
328
350
</div>"""
329
351
)
330
352
with gr .Tab ("Article Updating" ):
353
+ gr .Markdown ("### Reference examples can be found in the subsequent tab." )
331
354
input_1 = gr .Textbox (label = "Non-updated Article" , lines = 2 , placeholder = "Input the contexts..." )
332
355
input_2 = gr .Textbox (label = "Triggered News Event" , lines = 1 , placeholder = "Input the triggered news event..." )
333
- btn = gr .Button (value = "Submit" )
334
356
with gr .Row ():
335
- output_1 = gr .Textbox (label = "Updated Article" , lines = 5 )
336
- output_2 = gr .Textbox (label = "#MODIFIED / #ALL" )
357
+ gr .ClearButton ([input_1 , input_2 ])
358
+ btn = gr .Button (value = "Submit" )
359
+ with gr .Row ():
360
+ # output_1 = gr.Textbox(label="Non-updated Article", lines=5, placeholder="Please fill the textboxes above, then click 'Submit'")
361
+ output_1 = gr .HighlightedText (label = "Non-updated Article" )
362
+ # output_2 = gr.Textbox(label="Updated Article", lines=5)
363
+ output_2 = gr .HighlightedText (label = "Updated Article" )
337
364
btn .click (fn = main , inputs = [input_1 , input_2 ], outputs = [output_1 , output_2 ])
338
- btn_copy = gr .Button (value = "Copy Updated Article to Clipboard" )
339
- btn_copy .click (fn = copy_to_clipboard , inputs = [output_1 ], outputs = [])
365
+ btn_copy = gr .Button (value = "Copy Updated Article to clipboard" )
366
+ btn_copy .click (fn = copy_to_clipboard , inputs = [output_2 ], outputs = [])
367
+
368
+ com_1_value , com_2_value = "Pls finish article updating, then click the button above" , "Pls finish article updating, then click the button above."
369
+ # with gr.Tab("Compare between versions"):
370
+ # btn_com = gr.Button(value="Differences Highlighting")
371
+ # with gr.Row():
372
+ # com_1 = gr.Textbox(label="Non-update Paragraphs", value=com_1_value, lines=15)
373
+ # com_2 = gr.Textbox(label="Updated Paragraphs", value=com_2_value, lines=15)
374
+ # btn_com.click(fn=compare_versions, inputs=[], outputs=[com_1, com_2])
375
+ with gr .Tab ("Examples" ):
340
376
gr .Markdown ("## Input Examples" )
341
- gr .Markdown ("### There are 2 examples below, click them to test inputs automatically!" )
377
+ gr .Markdown ("### Two examples are provided below; please select one to auto-populate the inputs." )
378
+ gr .Markdown ("### Kindly select one of the provided examples, then return to the 'Article Updating' mode to assess the outcomes." )
342
379
gr .Examples (
343
380
examples = [[exin_1 , trigger_1 ], [exin_2 , trigger_2 ]],
344
381
fn = main ,
@@ -347,13 +384,7 @@ def compare_versions():
347
384
# cache_examples=True,
348
385
# run_on_click=True,
349
386
),
350
- com_1_value , com_2_value = "Pls finish article updating, then click the button above" , "Pls finish article updating, then click the button above."
351
- with gr .Tab ("Compare between versions" ):
352
- btn_com = gr .Button (value = "Differences Highlighting" )
353
- with gr .Row ():
354
- com_1 = gr .Textbox (label = "Non-update Article" , value = com_1_value , lines = 15 )
355
- com_2 = gr .Textbox (label = "Updated Article" , value = com_2_value , lines = 15 )
356
- btn_com .click (fn = compare_versions , inputs = [], outputs = [com_1 , com_2 ])
387
+
357
388
gr .HTML ("""
358
389
<div align="center">
359
390
<p>
0 commit comments