Qifan Zhang
commited on
Commit
·
613e689
1
Parent(s):
e32f803
update flexibility
Browse files- app.py +10 -24
- utils/pipeline.py +3 -8
app.py
CHANGED
@@ -18,11 +18,12 @@ def read_data(filepath: str) -> Optional[pd.DataFrame]:
|
|
18 |
return df
|
19 |
|
20 |
|
21 |
-
def process(
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
# try:
|
27 |
# load file
|
28 |
if file:
|
@@ -56,36 +57,21 @@ task_name_dropdown = gr.components.Dropdown(
|
|
56 |
value='Originality',
|
57 |
choices=['Originality', 'Flexibility']
|
58 |
)
|
59 |
-
|
60 |
model_name_dropdown = gr.components.Dropdown(
|
61 |
label='Model Name',
|
62 |
value=list_models[0],
|
63 |
choices=list_models
|
64 |
)
|
65 |
-
|
66 |
text_input = gr.components.Textbox(
|
67 |
value=open('data/example_xlm.csv', 'r').read(),
|
68 |
lines=10,
|
69 |
-
type='text'
|
70 |
)
|
|
|
71 |
|
72 |
# output
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
text_output = gr.components.Textbox(
|
78 |
-
label='Output',
|
79 |
-
type='text'
|
80 |
-
)
|
81 |
-
|
82 |
-
dataframe_output = gr.components.Dataframe(
|
83 |
-
label='DataFrame'
|
84 |
-
)
|
85 |
-
|
86 |
-
file_output = gr.components.File(label='Output File',
|
87 |
-
file_count='single',
|
88 |
-
file_types=['', '.', '.csv', '.xls', '.xlsx'])
|
89 |
|
90 |
app = gr.Interface(
|
91 |
fn=process,
|
|
|
18 |
return df
|
19 |
|
20 |
|
21 |
+
def process(
|
22 |
+
task_name: str,
|
23 |
+
model_name: str,
|
24 |
+
text: str,
|
25 |
+
file=None,
|
26 |
+
) -> (None, pd.DataFrame, str):
|
27 |
# try:
|
28 |
# load file
|
29 |
if file:
|
|
|
57 |
value='Originality',
|
58 |
choices=['Originality', 'Flexibility']
|
59 |
)
|
|
|
60 |
model_name_dropdown = gr.components.Dropdown(
|
61 |
label='Model Name',
|
62 |
value=list_models[0],
|
63 |
choices=list_models
|
64 |
)
|
|
|
65 |
text_input = gr.components.Textbox(
|
66 |
value=open('data/example_xlm.csv', 'r').read(),
|
67 |
lines=10,
|
|
|
68 |
)
|
69 |
+
file_input = gr.components.File(label='Input File', file_types=['.csv', '.xlsx'])
|
70 |
|
71 |
# output
|
72 |
+
text_output = gr.components.Textbox(label='Output')
|
73 |
+
dataframe_output = gr.components.Dataframe(label='DataFrame')
|
74 |
+
file_output = gr.components.File(label='Output File', file_types=['.csv', '.xlsx'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
app = gr.Interface(
|
77 |
fn=process,
|
utils/pipeline.py
CHANGED
@@ -41,15 +41,10 @@ def p1_flexibility(df: pd.DataFrame, model_name: str) -> pd.DataFrame:
|
|
41 |
|
42 |
def get_flexibility(responses: List[str]) -> float:
|
43 |
responses_vec = [model(_) for _ in responses]
|
44 |
-
count = 0
|
45 |
score = 0
|
46 |
-
for i in range(len(responses_vec)):
|
47 |
-
|
48 |
-
|
49 |
-
continue
|
50 |
-
score += 1 - cos_sim(responses_vec[i], responses_vec[j]).item()
|
51 |
-
count += 1
|
52 |
-
return score / count
|
53 |
|
54 |
df_out = df.groupby(by=['id', 'prompt']) \
|
55 |
.agg({'id': 'first', 'prompt': 'first', 'response': get_flexibility}) \
|
|
|
41 |
|
42 |
def get_flexibility(responses: List[str]) -> float:
|
43 |
responses_vec = [model(_) for _ in responses]
|
|
|
44 |
score = 0
|
45 |
+
for i in range(len(responses_vec) - 1):
|
46 |
+
score += 1 - cos_sim(responses_vec[i], responses_vec[i + 1]).item()
|
47 |
+
return score
|
|
|
|
|
|
|
|
|
48 |
|
49 |
df_out = df.groupby(by=['id', 'prompt']) \
|
50 |
.agg({'id': 'first', 'prompt': 'first', 'response': get_flexibility}) \
|