Update classification.py
Browse files- classification.py +35 -0
classification.py
CHANGED
@@ -4,6 +4,41 @@ from sentence_transformers import SentenceTransformer, util
|
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def load_data(file_obj):
|
8 |
# Assuming file_obj is a file-like object uploaded via Gradio, use `pd.read_excel` directly on it
|
9 |
return pd.read_excel(file_obj)
|
|
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
|
7 |
+
### Functions needed for Classfication
|
8 |
+
|
9 |
+
def addCategories(df,df_all):
|
10 |
+
categories = df.to_dict("records")
|
11 |
+
categories_all = df_all.to_dict("list")
|
12 |
+
for cat in categories:
|
13 |
+
if cat['topic'] not in categories_all['topic']:
|
14 |
+
categories_all['topic'].append(cat['topic'])
|
15 |
+
categories_all['description'].append(cat['description'])
|
16 |
+
categories_all['experts'].append(cat['experts'])
|
17 |
+
print(f"AFTER ADDINGS Those are the categories_all : {categories_all}")
|
18 |
+
|
19 |
+
return gr.update(choices=categories_all['topic']),pd.DataFrame.from_dict(categories_all)
|
20 |
+
|
21 |
+
df_cat_filter = df_cate.to_dict("list")["topic"]
|
22 |
+
|
23 |
+
def filterByTopics(filters, categories):
|
24 |
+
value_filtered = []
|
25 |
+
categories = categories.to_dict("records")
|
26 |
+
for cat in categories:
|
27 |
+
if cat['topic'] in filters:
|
28 |
+
value_filtered.append(cat)
|
29 |
+
|
30 |
+
return gr.DataFrame(label='categories', value=pd.DataFrame(value_filtered), interactive=True)
|
31 |
+
|
32 |
+
### End
|
33 |
+
|
34 |
+
def reset_cate(df_categories):
|
35 |
+
if df_categories.equals(df_cate):
|
36 |
+
df_categories = pd.DataFrame([['', '', '']], columns=['topic', 'description', 'expert'])
|
37 |
+
else:
|
38 |
+
df_categories = df_cate.copy()
|
39 |
+
return df_categories
|
40 |
+
|
41 |
+
|
42 |
def load_data(file_obj):
|
43 |
# Assuming file_obj is a file-like object uploaded via Gradio, use `pd.read_excel` directly on it
|
44 |
return pd.read_excel(file_obj)
|