ethanlim04 commited on
Commit
1791149
·
verified ·
1 Parent(s): 9f549a4

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -0
main.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib
3
+ import models
4
+ import utils
5
+
6
+ def infer(gt: str, data: str) -> matplotlib.figure:
7
+ nli_res = models.compute_metric(gt, data)
8
+ tone_res = models.compare_tone(gt, data)
9
+ res_text = ""
10
+ if (nli_res["label"] == "neutral"):
11
+ res_text += "Model's response is unrelated to the Ground Truth\nNeutral relationship"
12
+ if (nli_res["label"] == "contradiction"):
13
+ res_text += "Model's response contradicts the Ground Truth\nWeak relationship"
14
+ if (nli_res["label"] == "entailment"):
15
+ res_text += "Model's response is consistant with the Ground Truth"
16
+ if (nli_res[nli_res["label"]] > 0.9):
17
+ res_text += "\nStrong relationship"
18
+ return res_text, utils.create_pie_chart_nli(nli_res), utils.plot_tones(tone_res)
19
+
20
+ examples = [["Cross-encoders are better than bi-encoders for analyzing the relationship betwen texts", "Bi-encoders are superior to cross-encoders"],
21
+ ["Cross-encoders are better than bi-encoders for analyzing the relationship betwen texts", "The cosine similarity function can be used to compare the outputs of a bi-encoder"],
22
+ ["Cross-encoders are better than bi-encoders for analyzing the relationship betwen texts", "Bi-encoders are outperformed by cross-encoders in the task of relationship analysis"],
23
+ ["Birds can fly. There are fish in the sea.", "Fish inhabit the ocean. Birds can aviate."],
24
+ ["Birds can fly. There are fish in the sea.", "Fish inhabit the ocean. Birds can not aviate."]]
25
+ app = gr.Interface(fn=infer, inputs=[gr.Textbox(label="Ground Truth"), gr.Textbox(label="Model Response")], examples=examples, outputs=[gr.Textbox(label="Result"), gr.Plot(label="Comparison with GT"), gr.Plot(label="Difference in Tone")])
26
+ app.launch()