kz209 commited on
Commit
143b62d
β€’
1 Parent(s): f86ab54
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
 
3
  from pages.arena import create_arena
4
- from pages.summarization_example import create_summarization_interface
5
  from pages.leaderboard import create_leaderboard
6
 
7
  def welcome_message():
@@ -22,12 +22,14 @@ with gr.Blocks() as demo:
22
  )
23
 
24
  with gr.Tabs() as tabs:
25
- with gr.TabItem("Demo_of_Streaming"):
26
- create_arena()
27
  with gr.TabItem("Summarization"):
28
  create_summarization_interface()
29
  with gr.TabItem("Leaderboard"):
30
  create_leaderboard()
 
 
 
 
31
 
32
 
33
  if __name__ == "__main__":
 
1
  import gradio as gr
2
 
3
  from pages.arena import create_arena
4
+ from pages.summarization_playground import create_summarization_interface
5
  from pages.leaderboard import create_leaderboard
6
 
7
  def welcome_message():
 
22
  )
23
 
24
  with gr.Tabs() as tabs:
 
 
25
  with gr.TabItem("Summarization"):
26
  create_summarization_interface()
27
  with gr.TabItem("Leaderboard"):
28
  create_leaderboard()
29
+ with gr.TabItem("Batch_Evaluation"):
30
+ create_arena()
31
+ with gr.TabItem("Demo_of_Streaming"):
32
+ create_arena()
33
 
34
 
35
  if __name__ == "__main__":
pages/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # This is the __init__.py file for the utils package
2
+ # You can add any initialization code or import statements here
3
+
4
+ __all__ = ['arena', 'batch_evaluation', 'leaderboard', 'summarization_playground']
pages/batch_evaluation.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import gradio as gr
3
+ import random
4
+
5
+ from utils.model import Model
6
+ from utils.data import dataset
7
+ from utils.metric import metric_rouge_score
8
+
9
+ from summarization_playground import model, generate_answer
10
+
11
+ load_dotenv()
12
+
13
+ def process(seed, model_selection, prompt, num=10):
14
+ random.seed(seed)
15
+ response_list = []
16
+
17
+ for data in random.choices(dataset, k=num):
18
+ dialogue = data['dialogue']
19
+ summary = data['summary']
20
+ response = generate_answer(dialogue, model, model_selection, prompt)
21
+
22
+ rouge_score = metric_rouge_score(response, summary)
23
+
24
+ response_list.append(
25
+ {
26
+ 'dialogue': dialogue,
27
+ 'summary': summary,
28
+ 'response': response,
29
+ 'metric_score': {
30
+ 'rouge_score': rouge_score
31
+ }
32
+ }
33
+ )
34
+
35
+ return response_list
36
+
37
+ def create_batch_evaluation_interface():
38
+ with gr.blocks() as demo:
39
+ gr.Markdown("## Here are evaluation setups")
40
+ with gr.Row():
41
+ seed = gr.Number(value=8, placeholder="pick your favoriate random seed")
42
+ model_dropdown = gr.Dropdown(choices=Model.__model_list__, label="Choose a model", value=Model.__model_list__[0])
43
+ Template_text = gr.Textbox(value="""Summariza the following dialogue""", label='Input Prompting Template', lines=8, placeholder='Input your prompts')
44
+ submit_button = gr.Button("✨ Submit ✨")
45
+ output = gr.Markdown()
46
+
47
+ submit_button.click(
48
+ process,
49
+ inputs=[seed, model_dropdown, Template_text],
50
+ outputs=output
51
+ )
52
+
53
+ return demo
54
+
55
+ if __name__ == "__main__":
56
+ demo = create_batch_evaluation_interface()
57
+ demo.launch()
pages/{summarization_example.py β†’ summarization_playground.py} RENAMED
@@ -7,11 +7,7 @@ from utils.data import dataset
7
 
8
  load_dotenv()
9
 
10
- __model_list__ = [
11
- "lmsys/vicuna-7b-v1.5",
12
- "tiiuae/falcon-7b-instruct"
13
- ]
14
- model = {model_name: Model(model_name) for model_name in __model_list__}
15
 
16
  random_label = 'πŸ”€ Random dialogue from dataset'
17
  examples = {
@@ -31,7 +27,7 @@ Back in Boston, Kidd is going to rely on Lively even more. He'll play close to 3
31
  random_label: ""
32
  }
33
 
34
- def generate_answer(sources, model_name, prompt):
35
  assert "{sources}" in prompt, ValueError("No {sources} Found")
36
 
37
  meta_prompt = prompt
@@ -42,7 +38,7 @@ def generate_answer(sources, model_name, prompt):
42
 
43
  def process_input(input_text, model_selection, prompt):
44
  if input_text:
45
- response = generate_answer(input_text, model_selection, prompt)
46
  return f"## Original Article:\n\n{input_text}\n\n## Summarization:\n\n{response}"
47
  else:
48
  return "Please fill the input to generate outputs."
@@ -54,15 +50,13 @@ def update_input(example):
54
 
55
  def create_summarization_interface():
56
  with gr.Blocks() as demo:
57
- gr.Markdown("## This is an example to show summarization")
58
 
59
  with gr.Row():
60
  example_dropdown = gr.Dropdown(choices=list(examples.keys()), label="Choose an example")
61
- model_dropdown = gr.Dropdown(choices=["lmsys/vicuna-7b-v1.5", "tiiuae/falcon-7b-instruct"], label="Choose a model", value="lmsys/vicuna-7b-v1.5")
62
 
63
- Template_text = gr.Textbox(value="""{sources}
64
-
65
- summarization: """, label='Input Prompting Template', lines=8, placeholder='Input your prompts, must include \{sources\}')
66
 
67
  input_text = gr.Textbox(label="Input Text", lines=10, placeholder="Enter text here...")
68
  submit_button = gr.Button("✨ Submit ✨")
 
7
 
8
  load_dotenv()
9
 
10
+ model = {model_name: Model(model_name) for model_name in Model.__model_list__}
 
 
 
 
11
 
12
  random_label = 'πŸ”€ Random dialogue from dataset'
13
  examples = {
 
27
  random_label: ""
28
  }
29
 
30
+ def generate_answer(sources, model, model_name, prompt):
31
  assert "{sources}" in prompt, ValueError("No {sources} Found")
32
 
33
  meta_prompt = prompt
 
38
 
39
  def process_input(input_text, model_selection, prompt):
40
  if input_text:
41
+ response = generate_answer(input_text, model, model_selection, prompt)
42
  return f"## Original Article:\n\n{input_text}\n\n## Summarization:\n\n{response}"
43
  else:
44
  return "Please fill the input to generate outputs."
 
50
 
51
  def create_summarization_interface():
52
  with gr.Blocks() as demo:
53
+ gr.Markdown("## This is a playground to test summarizations")
54
 
55
  with gr.Row():
56
  example_dropdown = gr.Dropdown(choices=list(examples.keys()), label="Choose an example")
57
+ model_dropdown = gr.Dropdown(choices=Model.__model_list__, label="Choose a model", value=Model.__model_list__[0])
58
 
59
+ Template_text = gr.Textbox(value="""Summariza the following dialogue""", label='Input Prompting Template', lines=8, placeholder='Input your prompts, must include \{sources\}')
 
 
60
 
61
  input_text = gr.Textbox(label="Input Text", lines=10, placeholder="Enter text here...")
62
  submit_button = gr.Button("✨ Submit ✨")
utils/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
  # This is the __init__.py file for the utils package
2
  # You can add any initialization code or import statements here
3
 
4
- __all__ = ['multiple_stream', 'model']
 
1
  # This is the __init__.py file for the utils package
2
  # You can add any initialization code or import statements here
3
 
4
+ __all__ = ['multiple_stream', 'model', 'data', 'metric']
utils/metric.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from rouge_score import rouge_scorer
2
+
3
+ scorer = rouge_scorer.RougeScorer(['rougeL'], use_stemmer=True)
4
+
5
+ def metric_rouge_score(pred, ref):
6
+ return scorer.score(pred, ref)['rougeL'].fmeasure
utils/model.py CHANGED
@@ -4,6 +4,10 @@ import torch
4
 
5
  class Model():
6
  number_of_models = 0
 
 
 
 
7
 
8
  def __init__(self, model_name="lmsys/vicuna-7b-v1.5") -> None:
9
  self.tokenizer = AutoTokenizer.from_pretrained(model_name)
 
4
 
5
  class Model():
6
  number_of_models = 0
7
+ __model_list__ = [
8
+ "lmsys/vicuna-7b-v1.5",
9
+ "tiiuae/falcon-7b-instruct"
10
+ ]
11
 
12
  def __init__(self, model_name="lmsys/vicuna-7b-v1.5") -> None:
13
  self.tokenizer = AutoTokenizer.from_pretrained(model_name)