IAMJB commited on
Commit
e8158c1
·
1 Parent(s): bc9f889

cosmetic change

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import gradio as gr
2
- import pandas as pd
3
  from green_score import GREEN
4
  import spaces
5
 
6
- @spaces.GPU # Add the GPU decorator for functions that need GPU access
 
7
  def run_green(ref_text, hyp_text, model_name="StanfordAIMI/GREEN-radllama2-7b"):
8
  refs = [ref_text.strip()]
9
  hyps = [hyp_text.strip()]
@@ -11,13 +11,16 @@ def run_green(ref_text, hyp_text, model_name="StanfordAIMI/GREEN-radllama2-7b"):
11
  green_scorer = GREEN(model_name, output_dir=".")
12
  mean, std, green_score_list, summary, result_df = green_scorer(refs, hyps)
13
 
14
- final_summary = (
15
- f"**Model:** {model_name}\n\n"
16
- f"**Mean GREEN Score:** {mean:.4f}\n"
17
- f"**Std Deviation:** {std:.4f}\n\n"
18
- f"**Detailed Summary:**\n{summary}"
19
- )
20
- return final_summary, pd.DataFrame(result_df), green_score_list
 
 
 
21
 
22
  # Example pairs
23
  examples = {
@@ -35,11 +38,14 @@ examples = {
35
  }
36
  }
37
 
 
38
  def update_fields(choice):
39
  if choice == "Custom":
40
  return gr.update(value="", interactive=True), gr.update(value="", interactive=True)
41
  else:
42
- return gr.update(value=examples[choice]["ref"], interactive=False), gr.update(value=examples[choice]["hyp"], interactive=False)
 
 
43
 
44
  with gr.Blocks(title="GREEN Score Evaluation Demo") as demo:
45
  gr.Markdown("# GREEN Score Evaluation Demo")
@@ -77,14 +83,20 @@ with gr.Blocks(title="GREEN Score Evaluation Demo") as demo:
77
  )
78
 
79
  run_button = gr.Button("Compute GREEN Score")
80
- summary_output = gr.Markdown()
81
- df_output = gr.DataFrame()
82
- score_list_output = gr.JSON()
 
 
 
 
 
 
83
 
84
  run_button.click(
85
  run_green,
86
  inputs=[ref_input, hyp_input, model_name_input],
87
- outputs=[summary_output, df_output, score_list_output]
88
  )
89
 
90
  demo.launch()
 
1
  import gradio as gr
 
2
  from green_score import GREEN
3
  import spaces
4
 
5
+
6
+ @spaces.GPU(duration=120) # Add the GPU decorator for functions that need GPU access
7
  def run_green(ref_text, hyp_text, model_name="StanfordAIMI/GREEN-radllama2-7b"):
8
  refs = [ref_text.strip()]
9
  hyps = [hyp_text.strip()]
 
11
  green_scorer = GREEN(model_name, output_dir=".")
12
  mean, std, green_score_list, summary, result_df = green_scorer(refs, hyps)
13
 
14
+ green_analysis_text = result_df["green_analysis"].iloc[0]
15
+
16
+ # Prepare data for the nx2 table
17
+ table_data = []
18
+ for key, value in result_df.iloc[0].to_dict().items():
19
+ if key not in ["reference", "predictions", "green_analysis"]:
20
+ table_data.append([key, value])
21
+
22
+ return green_analysis_text, table_data
23
+
24
 
25
  # Example pairs
26
  examples = {
 
38
  }
39
  }
40
 
41
+
42
  def update_fields(choice):
43
  if choice == "Custom":
44
  return gr.update(value="", interactive=True), gr.update(value="", interactive=True)
45
  else:
46
+ return gr.update(value=examples[choice]["ref"], interactive=False), gr.update(value=examples[choice]["hyp"],
47
+ interactive=False)
48
+
49
 
50
  with gr.Blocks(title="GREEN Score Evaluation Demo") as demo:
51
  gr.Markdown("# GREEN Score Evaluation Demo")
 
83
  )
84
 
85
  run_button = gr.Button("Compute GREEN Score")
86
+ green_analysis_output = gr.Textbox(
87
+ label="GREEN Analysis",
88
+ lines=10,
89
+ interactive=False
90
+ )
91
+ table_output = gr.DataFrame(
92
+ label="Scores and Errors",
93
+ headers=["Metric", "Value"]
94
+ )
95
 
96
  run_button.click(
97
  run_green,
98
  inputs=[ref_input, hyp_input, model_name_input],
99
+ outputs=[green_analysis_output, table_output]
100
  )
101
 
102
  demo.launch()