Commit
·
48307cf
1
Parent(s):
987fcaa
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
|
|
5 |
import spacy
|
6 |
import torch
|
7 |
import plotly.express as px
|
@@ -63,7 +64,7 @@ def compare_text(transcript, categories, threshold):
|
|
63 |
phrases = torch.stack(phrases_list)
|
64 |
cosine_scores = util.cos_sim(embeddings, phrases).numpy()
|
65 |
max_scores = np.max(cosine_scores, axis=1)
|
66 |
-
df_cosines[df_category.iloc[0,2]] =
|
67 |
for num_sentence, scores in enumerate(cosine_scores):
|
68 |
for num_phrase, score in enumerate(scores):
|
69 |
if score >= threshold:
|
@@ -72,12 +73,11 @@ def compare_text(transcript, categories, threshold):
|
|
72 |
'sentence': sentences[num_sentence],
|
73 |
'phrase': df_category.at[num_phrase,'example'],
|
74 |
'category': df_category.at[num_phrase,'label'],
|
75 |
-
'similarity': score
|
76 |
}
|
77 |
df_results = df_results.append(new_row, ignore_index=True)
|
78 |
|
79 |
-
|
80 |
-
df_results = df_results.sort_values(['line','similarity'],ascending=[True,False]).round(decimals = 3)
|
81 |
|
82 |
df_summary = pd.DataFrame(df_cosines.max(numeric_only=True),columns=['similarity'])
|
83 |
df_summary['ok'] = np.where(df_summary['similarity'] > threshold, True, False)
|
@@ -99,8 +99,7 @@ def compare_text(transcript, categories, threshold):
|
|
99 |
fig.update_traces(textfont_size=24, textangle=0, textposition="inside", cliponaxis=False)
|
100 |
fig.update_yaxes(range=[0, 1])
|
101 |
|
102 |
-
|
103 |
-
df_summary = df_summary['similarity'].round(decimals = 2)
|
104 |
|
105 |
return df_summary.to_dict(), fig, df_cosines, df_results
|
106 |
|
|
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
+
import math
|
6 |
import spacy
|
7 |
import torch
|
8 |
import plotly.express as px
|
|
|
64 |
phrases = torch.stack(phrases_list)
|
65 |
cosine_scores = util.cos_sim(embeddings, phrases).numpy()
|
66 |
max_scores = np.max(cosine_scores, axis=1)
|
67 |
+
df_cosines[df_category.iloc[0,2]] = math.ceil(max_scores * 1000) / 1000.0
|
68 |
for num_sentence, scores in enumerate(cosine_scores):
|
69 |
for num_phrase, score in enumerate(scores):
|
70 |
if score >= threshold:
|
|
|
73 |
'sentence': sentences[num_sentence],
|
74 |
'phrase': df_category.at[num_phrase,'example'],
|
75 |
'category': df_category.at[num_phrase,'label'],
|
76 |
+
'similarity': math.ceil(score * 1000) / 1000.0
|
77 |
}
|
78 |
df_results = df_results.append(new_row, ignore_index=True)
|
79 |
|
80 |
+
df_results = df_results.sort_values(['line','similarity'],ascending=[True,False])
|
|
|
81 |
|
82 |
df_summary = pd.DataFrame(df_cosines.max(numeric_only=True),columns=['similarity'])
|
83 |
df_summary['ok'] = np.where(df_summary['similarity'] > threshold, True, False)
|
|
|
99 |
fig.update_traces(textfont_size=24, textangle=0, textposition="inside", cliponaxis=False)
|
100 |
fig.update_yaxes(range=[0, 1])
|
101 |
|
102 |
+
df_summary = df_summary['similarity']
|
|
|
103 |
|
104 |
return df_summary.to_dict(), fig, df_cosines, df_results
|
105 |
|