Update app.py
Browse files
app.py
CHANGED
|
@@ -86,26 +86,24 @@ def process_classification(text: str, model1, model2, tokenizer1) -> Tuple[str,
|
|
| 86 |
score = prediction1 / (prediction2 + prediction1)
|
| 87 |
|
| 88 |
return f"{round(prediction1, 1)}", f"{round(prediction2, 1)}", f"{round(score, 2)}"
|
| 89 |
-
|
| 90 |
-
def generate_charts(ner_output_bin: dict, ner_output_ext: dict) -> Tuple[plt.Figure, plt.Figure]:
|
| 91 |
-
entities_bin = [entity['entity'] for entity in ner_output_bin['entities']]
|
| 92 |
entities_ext = [entity['entity'] for entity in ner_output_ext['entities']]
|
|
|
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
pie_labels = list(entity_counts.keys())
|
| 98 |
-
pie_sizes = list(entity_counts.values())
|
| 99 |
|
| 100 |
fig1, ax1 = plt.subplots()
|
| 101 |
ax1.pie(pie_sizes, labels=pie_labels, autopct='%1.1f%%', startangle=90)
|
| 102 |
ax1.axis('equal')
|
| 103 |
|
| 104 |
fig2, ax2 = plt.subplots()
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
ax2.
|
| 108 |
-
ax2.
|
|
|
|
| 109 |
|
| 110 |
return fig1, fig2
|
| 111 |
|
|
@@ -113,12 +111,12 @@ def generate_charts(ner_output_bin: dict, ner_output_ext: dict) -> Tuple[plt.Fig
|
|
| 113 |
def all(text: str):
|
| 114 |
ner_output_bin = process_ner(text, pipe_bin)
|
| 115 |
ner_output_ext = process_ner(text, pipe_ext)
|
| 116 |
-
|
| 117 |
|
| 118 |
-
pie_chart, bar_chart = generate_charts(ner_output_bin, ner_output_ext)
|
| 119 |
|
| 120 |
return (ner_output_bin, ner_output_ext,
|
| 121 |
-
|
| 122 |
pie_chart, bar_chart)
|
| 123 |
|
| 124 |
examples = [
|
|
@@ -150,8 +148,8 @@ iface = gr.Interface(
|
|
| 150 |
gr.Label(label="Internal Detail Count"),
|
| 151 |
gr.Label(label="External Detail Count"),
|
| 152 |
gr.Label(label="Approximated Internal Detail Ratio"),
|
| 153 |
-
gr.Plot(label="
|
| 154 |
-
gr.Plot(label="
|
| 155 |
],
|
| 156 |
title="Scoring Demo",
|
| 157 |
description="Autobiographical Memory Analysis: This demo combines two text - and two sequence classification models to showcase our automated Autobiographical Interview scoring method. Submit a narrative to see the results.",
|
|
|
|
| 86 |
score = prediction1 / (prediction2 + prediction1)
|
| 87 |
|
| 88 |
return f"{round(prediction1, 1)}", f"{round(prediction2, 1)}", f"{round(score, 2)}"
|
| 89 |
+
|
| 90 |
+
def generate_charts(ner_output_bin: dict, ner_output_ext: dict, internal_count: float, external_count: float, score: float) -> Tuple[plt.Figure, plt.Figure]:
|
|
|
|
| 91 |
entities_ext = [entity['entity'] for entity in ner_output_ext['entities']]
|
| 92 |
+
entity_counts_ext = {entity: entities_ext.count(entity) for entity in set(entities_ext)}
|
| 93 |
|
| 94 |
+
pie_labels = list(entity_counts_ext.keys())
|
| 95 |
+
pie_sizes = list(entity_counts_ext.values())
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
fig1, ax1 = plt.subplots()
|
| 98 |
ax1.pie(pie_sizes, labels=pie_labels, autopct='%1.1f%%', startangle=90)
|
| 99 |
ax1.axis('equal')
|
| 100 |
|
| 101 |
fig2, ax2 = plt.subplots()
|
| 102 |
+
bars = ['Internal Detail Count', 'External Detail Count', 'Binary Classification Score']
|
| 103 |
+
values = [internal_count, external_count, float(score)]
|
| 104 |
+
ax2.bar(bars, values)
|
| 105 |
+
ax2.set_ylabel('Count/Score')
|
| 106 |
+
ax2.set_title('Internal vs External Details and Classification Score')
|
| 107 |
|
| 108 |
return fig1, fig2
|
| 109 |
|
|
|
|
| 111 |
def all(text: str):
|
| 112 |
ner_output_bin = process_ner(text, pipe_bin)
|
| 113 |
ner_output_ext = process_ner(text, pipe_ext)
|
| 114 |
+
internal_count, external_count, score = process_classification(text, model1, model2, tokenizer1)
|
| 115 |
|
| 116 |
+
pie_chart, bar_chart = generate_charts(ner_output_bin, ner_output_ext, float(internal_count), float(external_count), score)
|
| 117 |
|
| 118 |
return (ner_output_bin, ner_output_ext,
|
| 119 |
+
internal_count, external_count, score,
|
| 120 |
pie_chart, bar_chart)
|
| 121 |
|
| 122 |
examples = [
|
|
|
|
| 148 |
gr.Label(label="Internal Detail Count"),
|
| 149 |
gr.Label(label="External Detail Count"),
|
| 150 |
gr.Label(label="Approximated Internal Detail Ratio"),
|
| 151 |
+
gr.Plot(label="Extended Sequence Classification Pie Chart"),
|
| 152 |
+
gr.Plot(label="Internal vs External Details and Classification Score Bar Chart")
|
| 153 |
],
|
| 154 |
title="Scoring Demo",
|
| 155 |
description="Autobiographical Memory Analysis: This demo combines two text - and two sequence classification models to showcase our automated Autobiographical Interview scoring method. Submit a narrative to see the results.",
|