Spaces:
Sleeping
Sleeping
first push
Browse files- app.py +93 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from green_score import GREEN
|
| 4 |
+
|
| 5 |
+
# Include the GREEN class code here
|
| 6 |
+
# -------------------------------------
|
| 7 |
+
# Paste the GREEN class code above this line
|
| 8 |
+
# -------------------------------------
|
| 9 |
+
|
| 10 |
+
def run_green(ref_text, hyp_text, model_name="StanfordAIMI/GREEN-radllama2-7b"):
|
| 11 |
+
refs = [ref_text.strip()]
|
| 12 |
+
hyps = [hyp_text.strip()]
|
| 13 |
+
|
| 14 |
+
green_scorer = GREEN(model_name, output_dir=".")
|
| 15 |
+
mean, std, green_score_list, summary, result_df = green_scorer(refs, hyps)
|
| 16 |
+
|
| 17 |
+
final_summary = (
|
| 18 |
+
f"**Model:** {model_name}\n\n"
|
| 19 |
+
f"**Mean GREEN Score:** {mean:.4f}\n"
|
| 20 |
+
f"**Std Deviation:** {std:.4f}\n\n"
|
| 21 |
+
f"**Detailed Summary:**\n{summary}"
|
| 22 |
+
)
|
| 23 |
+
return final_summary, pd.DataFrame(result_df), green_score_list
|
| 24 |
+
|
| 25 |
+
# Example pairs
|
| 26 |
+
examples = {
|
| 27 |
+
"Example 1": {
|
| 28 |
+
"ref": "Interstitial opacities without changes.",
|
| 29 |
+
"hyp": "Interstitial opacities at bases without changes.",
|
| 30 |
+
},
|
| 31 |
+
"Example 2": {
|
| 32 |
+
"ref": "The heart size is normal. Lungs are clear without any infiltrates.",
|
| 33 |
+
"hyp": "The heart size is mildly enlarged. Mild infiltrates in the left upper lobe.",
|
| 34 |
+
},
|
| 35 |
+
"Example 3": {
|
| 36 |
+
"ref": "Lung volumes are low, causing bronchovascular crowding. The cardiomediastinal silhouette is unremarkable.",
|
| 37 |
+
"hyp": "Endotracheal tubes have been removed. Pulmonary aeration is slightly improved with no pleural effusions.",
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
def update_fields(choice):
|
| 42 |
+
if choice == "Custom":
|
| 43 |
+
return gr.update(value="", interactive=True), gr.update(value="", interactive=True)
|
| 44 |
+
else:
|
| 45 |
+
return gr.update(value=examples[choice]["ref"], interactive=False), gr.update(value=examples[choice]["hyp"], interactive=False)
|
| 46 |
+
|
| 47 |
+
with gr.Blocks(title="GREEN Score Evaluation Demo") as demo:
|
| 48 |
+
gr.Markdown("# GREEN Score Evaluation Demo")
|
| 49 |
+
gr.Markdown(
|
| 50 |
+
"This demo evaluates a single pair of reference and hypothesis reports to compute the GREEN score."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
with gr.Row():
|
| 54 |
+
choice = gr.Radio(
|
| 55 |
+
label="Choose Input Type",
|
| 56 |
+
choices=["Custom"] + list(examples.keys()),
|
| 57 |
+
value="Example 1",
|
| 58 |
+
interactive=True
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
ref_input = gr.Textbox(
|
| 62 |
+
label="Reference Report",
|
| 63 |
+
lines=3
|
| 64 |
+
)
|
| 65 |
+
hyp_input = gr.Textbox(
|
| 66 |
+
label="Hypothesis Report",
|
| 67 |
+
lines=3
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
choice.change(
|
| 71 |
+
update_fields,
|
| 72 |
+
inputs=choice,
|
| 73 |
+
outputs=[ref_input, hyp_input],
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
model_name_input = gr.Textbox(
|
| 77 |
+
label="Model Name",
|
| 78 |
+
value="StanfordAIMI/GREEN-radllama2-7b",
|
| 79 |
+
placeholder="Enter the HuggingFace model name"
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
run_button = gr.Button("Compute GREEN Score")
|
| 83 |
+
summary_output = gr.Markdown()
|
| 84 |
+
df_output = gr.DataFrame()
|
| 85 |
+
score_list_output = gr.JSON()
|
| 86 |
+
|
| 87 |
+
run_button.click(
|
| 88 |
+
run_green,
|
| 89 |
+
inputs=[ref_input, hyp_input, model_name_input],
|
| 90 |
+
outputs=[summary_output, df_output, score_list_output]
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
green_score
|
| 2 |
+
gradio
|