frt03 commited on
Commit
ecadb03
1 Parent(s): b3912be

update user interface

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -13,7 +13,7 @@ import google.generativeai as genai
13
 
14
 
15
  # Set up LLM APIs
16
- llm_api_options = ['gemini-pro', 'gemini-1.5-flash', 'gpt-3.5-turbo-1106']
17
 
18
  def query_gpt_model(
19
  prompt: str,
@@ -59,9 +59,14 @@ def query_gemini_model(
59
  ) -> str:
60
  del client
61
  model = genai.GenerativeModel(llm)
 
62
  while True and retries > 0:
63
  try:
64
- response = model.generate_content(prompt, safety_settings=safety_settings)
 
 
 
 
65
  text_response = response.text.replace("**", "")
66
  return text_response
67
  except Exception as e:
@@ -118,6 +123,8 @@ with open('QuALITY.v1.0.1.htmlstripped.dev', 'r') as f:
118
 
119
  quality_dev.append(fields)
120
 
 
 
121
 
122
 
123
  # Helper functions
@@ -419,7 +426,7 @@ def query_model_with_quality(
419
  # api_key = os.environ.get('GEMINI_API_KEY')
420
  genai.configure(api_key=api_key)
421
 
422
- example = quality_dev[index]
423
  article = f"[Title: {example['title']}]\n\n{example['article']}"
424
  pages, pagination = quality_pagination(example, model_name, client)
425
  print('Finish Pagination.')
@@ -446,7 +453,7 @@ with gr.Blocks() as demo:
446
  We implement ReadAgent as a simple prompting system that uses the advanced language capabilities of LLMs to (1) decide what content to store together in a memory episode (**Episode Pagination**), (2) compress those memory episodes into short episodic memories called gist memories (**Memory Gisting**), and (3) take actions to look up passages in the original text if ReadAgent needs to remind itself of relevant details to complete a task (**Parallel Lookup and QA**)
447
  This demo can handle long-document reading comprehension tasks ([QuALITY](https://arxiv.org/abs/2112.08608); max 6,000 words) efficiently.
448
 
449
- To get started, you can choose an index of QuALITY dataset.
450
  This demo uses Gemini API or OpenAI API so it requires the corresponding API key.
451
  """)
452
  with gr.Row():
@@ -457,9 +464,27 @@ with gr.Blocks() as demo:
457
  lines=1,
458
  type="password",
459
  )
460
- index = gr.Dropdown(list(range(len(quality_dev))), value=13, label="QuALITY Index")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  button = gr.Button("Execute")
462
- original_article = gr.Textbox(label="Original Article", lines=20)
463
  # prompt_pagination = gr.Textbox(label="Episode Pagination Prompt Template", lines=5)
464
  pagination_results = gr.Textbox(label="(1) Episode Pagination", lines=20)
465
  # prompt_gisting = gr.Textbox(label="Memory Gisting Prompt Template", lines=5)
@@ -478,7 +503,7 @@ with gr.Blocks() as demo:
478
  # prompt_pagination, pagination_results,
479
  # prompt_gisting, gisting_results,
480
  # prompt_lookup, lookup_qa_results,
481
- original_article,
482
  pagination_results,
483
  gisting_results,
484
  lookup_qa_results,
 
13
 
14
 
15
  # Set up LLM APIs
16
+ llm_api_options = ['gemini-pro', 'gemini-1.5-flash', 'gpt-3.5-turbo-1106', 'gpt-4o-2024-05-13', 'gpt-4o-mini-2024-07-18']
17
 
18
  def query_gpt_model(
19
  prompt: str,
 
59
  ) -> str:
60
  del client
61
  model = genai.GenerativeModel(llm)
62
+ generation_config={'temperature': 0.0}
63
  while True and retries > 0:
64
  try:
65
+ response = model.generate_content(
66
+ prompt,
67
+ safety_settings=safety_settings,
68
+ generation_config=generation_config
69
+ )
70
  text_response = response.text.replace("**", "")
71
  return text_response
72
  except Exception as e:
 
123
 
124
  quality_dev.append(fields)
125
 
126
+ # likely to succeed
127
+ index_map = {'A': 1, 'B': 9, 'C': 13, 'D': 200}
128
 
129
 
130
  # Helper functions
 
426
  # api_key = os.environ.get('GEMINI_API_KEY')
427
  genai.configure(api_key=api_key)
428
 
429
+ example = quality_dev[index_map[index]]
430
  article = f"[Title: {example['title']}]\n\n{example['article']}"
431
  pages, pagination = quality_pagination(example, model_name, client)
432
  print('Finish Pagination.')
 
453
  We implement ReadAgent as a simple prompting system that uses the advanced language capabilities of LLMs to (1) decide what content to store together in a memory episode (**Episode Pagination**), (2) compress those memory episodes into short episodic memories called gist memories (**Memory Gisting**), and (3) take actions to look up passages in the original text if ReadAgent needs to remind itself of relevant details to complete a task (**Parallel Lookup and QA**)
454
  This demo can handle long-document reading comprehension tasks ([QuALITY](https://arxiv.org/abs/2112.08608); max 6,000 words) efficiently.
455
 
456
+ To get started, you can choose an example article from QuALITY dataset.
457
  This demo uses Gemini API or OpenAI API so it requires the corresponding API key.
458
  """)
459
  with gr.Row():
 
464
  lines=1,
465
  type="password",
466
  )
467
+ # index = gr.Dropdown(list(range(len(quality_dev))), value=13, label="QuALITY Index")
468
+ index = gr.Radio(['A', 'B', 'C', 'D'], label="Example Article", value='A')
469
+ with gr.Row():
470
+ example_article_a = gr.Textbox(
471
+ label="Example Article (A)",
472
+ lines=10,
473
+ value=f"[Title: {quality_dev[index_map['A']]['title']}]\n\n{quality_dev[index_map['A']]['article']}")
474
+ example_article_a = gr.Textbox(
475
+ label="Example Article (B)",
476
+ lines=10,
477
+ value=f"[Title: {quality_dev[index_map['B']]['title']}]\n\n{quality_dev[index_map['B']]['article']}")
478
+ example_article_a = gr.Textbox(
479
+ label="Example Article (C)",
480
+ lines=10,
481
+ value=f"[Title: {quality_dev[index_map['C']]['title']}]\n\n{quality_dev[index_map['C']]['article']}")
482
+ example_article_a = gr.Textbox(
483
+ label="Example Article (D)",
484
+ lines=10,
485
+ value=f"[Title: {quality_dev[index_map['D']]['title']}]\n\n{quality_dev[index_map['D']]['article']}")
486
  button = gr.Button("Execute")
487
+ choosen_article = gr.Textbox(label="Choosen Original Article", lines=20)
488
  # prompt_pagination = gr.Textbox(label="Episode Pagination Prompt Template", lines=5)
489
  pagination_results = gr.Textbox(label="(1) Episode Pagination", lines=20)
490
  # prompt_gisting = gr.Textbox(label="Memory Gisting Prompt Template", lines=5)
 
503
  # prompt_pagination, pagination_results,
504
  # prompt_gisting, gisting_results,
505
  # prompt_lookup, lookup_qa_results,
506
+ choosen_article,
507
  pagination_results,
508
  gisting_results,
509
  lookup_qa_results,