Ali-Omrani commited on
Commit
fbae0f3
·
1 Parent(s): 5a24b39

trying out the old demo

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,7 +1,50 @@
1
  import pickle
2
  import os
3
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
 
 
5
 
6
 
7
 
@@ -9,5 +52,7 @@ demo = gr.Blocks()
9
  with demo:
10
  gr.Markdown('This is the first page for CCR, info goes here!')
11
 
 
 
12
 
13
  demo.launch()
 
1
  import pickle
2
  import os
3
  import gradio as gr
4
+ import gradio as gr
5
+ import pandas as pd
6
+ from sentence_transformers import SentenceTransformer, util
7
+
8
+ def encode_column(model, filename, col_name):
9
+ df = pd.read_csv(filename)
10
+ df["embedding"] = list(model.encode(df[col_name]))
11
+ return df
12
+
13
+ def item_level_ccr(data_encoded_df, questionnaire_encoded_df):
14
+ q_embeddings = questionnaire_encoded_df.embedding
15
+ d_embeddings = data_encoded_df.embedding
16
+ similarities = util.pytorch_cos_sim(d_embeddings, q_embeddings)
17
+ for i in range(1,len(questionnaire_encoded_df)+1):
18
+ data_encoded_df["sim_item_{}".format(i)] = similarities[:, i-1]
19
+ return data_encoded_df
20
+
21
+ # encoding questionnaire
22
+ def ccr_wrapper(data_file, data_col, q_file, q_col):
23
+
24
+ model = SentenceTransformer('all-MiniLM-L6-v2')
25
+ questionnaire_filename = q_file.name
26
+ data_filename = data_file.name
27
+ print(data_filename)
28
+
29
+ q_encoded_df = encode_column(model, questionnaire_filename , q_col)
30
+ data_encoded_df = encode_column(model, data_filename , data_col)
31
+
32
+ ccr_df = item_level_ccr(data_encoded_df, q_encoded_df)
33
+ # ccr_df = ccr_df.drop(columns=["embeddings"])
34
+
35
+ ccr_df.to_csv("ccr_results.csv")
36
+ return "ccr_results.csv"
37
+
38
+
39
+ def read_dataframe(data_file, data_col, q_file, q_col):
40
+
41
+ # df = pd.read_csv(data_file.name)
42
+ return data_file.name
43
+
44
+
45
 
46
+ iface = gr.Interface(ccr_wrapper, [gr.inputs.File(label="User Data File"), gr.inputs.Textbox(lines=1,label="User Text Column Title", placeholder="Name of the column contatining user's text ..."), gr.inputs.File(label="Questionnaire File"),gr.inputs.Textbox(lines=1, label="Questionnaire Text Column Title",placeholder="Name of the column containing questions") ], "file", examples=[["CCR_clean.csv", "ValuesSurvey","Questionnaire - MFQ2.csv", "question"]])
47
+ iface.launch(debug=True)
48
 
49
 
50
 
 
52
  with demo:
53
  gr.Markdown('This is the first page for CCR, info goes here!')
54
 
55
+ iface = gr.Interface(ccr_wrapper, [gr.inputs.File(label="User Data File"), gr.inputs.Textbox(lines=1,label="User Text Column Title", placeholder="Name of the column contatining user's text ..."), gr.inputs.File(label="Questionnaire File"),gr.inputs.Textbox(lines=1, label="Questionnaire Text Column Title",placeholder="Name of the column containing questions") ], "file", examples=[["CCR_clean.csv", "ValuesSurvey","Questionnaire - MFQ2.csv", "question"]])
56
+ iface.launch(debug=False)
57
 
58
  demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ sentence-transformers