Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,145 +1,324 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
def update_scores(
|
| 5 |
-
score_difference = k_factor / (
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
def
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return
|
| 21 |
|
| 22 |
-
def
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
def
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
def
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
return opponents_df
|
| 49 |
|
| 50 |
-
def
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
theme = gr.themes.Soft(primary_hue="red", secondary_hue="blue")
|
| 77 |
|
| 78 |
with gr.Blocks(theme=theme) as app:
|
| 79 |
-
gr.Markdown(
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
with gr.Tab("Criteria Ranking"):
|
| 82 |
-
gr.Markdown(
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
| 90 |
criteria_df = pd.DataFrame(columns=['score', 'criteria'])
|
| 91 |
criteria_rankings = gr.DataFrame(value=criteria_df, interactive=False, headers=["Score", "Criteria"])
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
criteria_new_vote.click(
|
| 108 |
-
inputs=[criteria_rankings], outputs=[criteria_compare_output, criteria_input, criteria_input])
|
| 109 |
|
| 110 |
with gr.Tab("Opponent Ranking"):
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
app.launch(share=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import re
|
| 4 |
+
import csv
|
| 5 |
|
| 6 |
+
def update_scores(winner, loser, k_factor=100):
|
| 7 |
+
score_difference = int(k_factor / (winner / loser))
|
| 8 |
+
winner += score_difference
|
| 9 |
+
loser -= score_difference
|
| 10 |
+
return winner, loser
|
| 11 |
|
| 12 |
+
def vote_startup_criteria(criteria_df):
|
| 13 |
+
if len(criteria_df) > 1:
|
| 14 |
+
sample = criteria_df.sample(n=2)
|
| 15 |
+
first_string = sample.iloc[0]["criteria"]
|
| 16 |
+
second_string = sample.iloc[1]["criteria"]
|
| 17 |
+
return f"Is '{first_string}' more important than '{second_string}'?", first_string, second_string, display_criteria_rankings(criteria_df)
|
| 18 |
+
else:
|
| 19 |
+
return "Add more criteria to start ranking!", "", "", display_criteria_rankings(criteria_df)
|
| 20 |
|
| 21 |
+
def vote_startup_opponents(opponents_df, criteria_df):
|
| 22 |
+
try:
|
| 23 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 24 |
+
except:
|
| 25 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 26 |
+
if len(opponents_df) > 0:
|
| 27 |
+
if len(opponents_df) > 10:
|
| 28 |
+
slice_size = 4
|
| 29 |
+
slice = int(len(opponents_df) / slice_size)
|
| 30 |
+
sample = opponents_df[slice:(slice_size - 1) * slice].sample(frac=1).iloc[0]
|
| 31 |
+
opponent, descriptor = sample["opponent"], sample["descriptor"]
|
| 32 |
+
else:
|
| 33 |
+
sample = opponents_df.sample(frac=1).iloc[0]
|
| 34 |
+
opponent, descriptor = sample["opponent"], sample["descriptor"]
|
| 35 |
+
if len(opponents_df) > 1:
|
| 36 |
+
sample = opponents_df.sample(frac=1)
|
| 37 |
+
comparison_opponent = sample.iloc[0]
|
| 38 |
+
if comparison_opponent['opponent'] == opponent and comparison_opponent['descriptor'] == descriptor:
|
| 39 |
+
comparison_opponent = sample.iloc[1]
|
| 40 |
+
first_df = opponents_df[opponents_df["opponent"] == opponent][opponents_df["descriptor"] == descriptor]
|
| 41 |
+
first_string = first_df["opponent"].tolist()[0] + " - " + first_df["descriptor"].tolist()[0]
|
| 42 |
+
second_df = comparison_opponent
|
| 43 |
+
second_string = second_df["opponent"] + " - " + second_df["descriptor"]
|
| 44 |
+
criteria = criteria_df.sample(n=1)["criteria"].values[0]
|
| 45 |
+
return f"Which opponent better represents '{criteria}': '{descriptor} - {opponent}' or '{comparison_opponent['descriptor']} - {comparison_opponent['opponent']}'?", first_string, second_string, criteria, display_rankings(opponents_df, criteria_df)
|
| 46 |
+
else:
|
| 47 |
+
return "Add some opponents to start voting!", "", "", "", display_rankings(opponents_df, criteria_df)
|
| 48 |
|
| 49 |
+
def clean_string(string):
|
| 50 |
+
string = string.strip().replace(" ", " ").lower()
|
| 51 |
+
string = " ".join([x[0].upper() + x[1:] for x in string.split()])
|
| 52 |
+
return string
|
| 53 |
|
| 54 |
+
def add_and_compare(descriptor, opponent, opponents_df, criteria_df):
|
| 55 |
+
try:
|
| 56 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 57 |
+
except:
|
| 58 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 59 |
+
if descriptor != "" and opponent != "":
|
| 60 |
+
descriptor = clean_string(descriptor)
|
| 61 |
+
opponent = clean_string(opponent)
|
| 62 |
+
new_opponent = pd.DataFrame({'descriptor': [descriptor], 'opponent': [opponent]})
|
| 63 |
+
for c in criteria_df["criteria"]:
|
| 64 |
+
new_opponent[f"{c}_score"] = 1000
|
| 65 |
+
new_opponent["overall_score"] = 1000
|
| 66 |
+
opponents_df = pd.concat([opponents_df, new_opponent], ignore_index=True)
|
| 67 |
+
opponents_df.to_csv("opponents_df.csv")
|
| 68 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 69 |
+
return "", "", display_rankings(opponents_df, criteria_df)
|
| 70 |
|
| 71 |
+
def update_ratings_pos(first_string, second_string, criteria, opponents_df, criteria_df):
|
| 72 |
+
try:
|
| 73 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 74 |
+
except:
|
| 75 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 76 |
+
if len(opponents_df) == 0:
|
| 77 |
+
return "Add some opponents to start voting!", "", "", "", display_rankings(opponents_df, criteria_df)
|
| 78 |
+
if first_string != "":
|
| 79 |
+
opponents_df["combined"] = opponents_df["opponent"] + " - " + opponents_df["descriptor"]
|
| 80 |
+
loser = opponents_df[opponents_df["combined"] == second_string]
|
| 81 |
+
winner = opponents_df[opponents_df["combined"] == first_string]
|
| 82 |
+
winner_score, loser_score = update_scores(winner[f"{criteria}_score"].values[0], loser[f"{criteria}_score"].values[0])
|
| 83 |
+
opponents_df.at[winner.index[0], f"{criteria}_score"] = winner_score
|
| 84 |
+
opponents_df.at[loser.index[0], f"{criteria}_score"] = loser_score
|
| 85 |
+
opponents_df = calculate_overall_scores(opponents_df, criteria_df)
|
| 86 |
+
opponents_df.to_csv("opponents_df.csv")
|
| 87 |
+
return vote_startup_opponents(opponents_df, criteria_df)
|
| 88 |
|
| 89 |
+
def update_ratings_neg(first_string, second_string, criteria, opponents_df, criteria_df):
|
| 90 |
+
try:
|
| 91 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 92 |
+
except:
|
| 93 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 94 |
+
if len(opponents_df) == 0:
|
| 95 |
+
return "Add some opponents to start voting!", "", "", "", display_rankings(opponents_df, criteria_df)
|
| 96 |
+
if first_string != "":
|
| 97 |
+
opponents_df["combined"] = opponents_df["opponent"] + " - " + opponents_df["descriptor"]
|
| 98 |
+
loser = opponents_df[opponents_df["combined"] == first_string]
|
| 99 |
+
winner = opponents_df[opponents_df["combined"] == second_string]
|
| 100 |
+
winner_score, loser_score = update_scores(winner[f"{criteria}_score"].values[0], loser[f"{criteria}_score"].values[0])
|
| 101 |
+
opponents_df.at[winner.index[0], f"{criteria}_score"] = winner_score
|
| 102 |
+
opponents_df.at[loser.index[0], f"{criteria}_score"] = loser_score
|
| 103 |
+
opponents_df = calculate_overall_scores(opponents_df, criteria_df)
|
| 104 |
+
opponents_df.to_csv("opponents_df.csv")
|
| 105 |
+
return vote_startup_opponents(opponents_df, criteria_df)
|
| 106 |
+
|
| 107 |
+
def display_rankings(opponents_df, criteria_df):
|
| 108 |
+
opponents_df = opponents_df.sort_values(by='overall_score', ascending=False)
|
| 109 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 110 |
+
opponents_df.to_csv("opponents_df.csv")
|
| 111 |
+
return opponents_df
|
| 112 |
|
| 113 |
+
def export_csv(opponents_df):
|
| 114 |
+
save_df = opponents_df
|
| 115 |
+
save_df.to_csv("opponents_df.csv")
|
| 116 |
+
return "opponents_df.csv"
|
| 117 |
|
| 118 |
+
def import_csv(file, opponents_df, criteria_df):
|
| 119 |
+
if file is not None:
|
| 120 |
+
new_df = pd.read_csv(file)
|
| 121 |
+
try:
|
| 122 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 123 |
+
except:
|
| 124 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 125 |
+
new_df = new_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 126 |
+
opponents_df = pd.concat([opponents_df, new_df])
|
| 127 |
+
opponents_df = opponents_df.drop_duplicates(subset=['descriptor', 'opponent'])
|
| 128 |
return opponents_df
|
| 129 |
|
| 130 |
+
def remove_opponent(descriptor, opponent, opponents_df):
|
| 131 |
+
descriptor = clean_string(descriptor)
|
| 132 |
+
opponent = clean_string(opponent)
|
| 133 |
+
opponents_df = opponents_df[~((opponents_df["descriptor"] == descriptor) & (opponents_df["opponent"] == opponent))]
|
| 134 |
+
return opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 135 |
+
|
| 136 |
+
def reset_rankings(opponents_df, criteria_df):
|
| 137 |
+
for c in criteria_df["criteria"]:
|
| 138 |
+
opponents_df[f"{c}_score"] = 1000
|
| 139 |
+
opponents_df["overall_score"] = 1000
|
| 140 |
+
opponents_df = opponents_df[["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"]]
|
| 141 |
+
return display_rankings(opponents_df, criteria_df)
|
| 142 |
+
|
| 143 |
+
def clear_rankings(opponents_df, criteria_df):
|
| 144 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 145 |
+
return display_rankings(opponents_df, criteria_df)
|
| 146 |
+
|
| 147 |
+
def add_criteria(criteria, criteria_df):
|
| 148 |
+
if criteria != "":
|
| 149 |
+
criteria = clean_string(criteria)
|
| 150 |
+
new_criteria = pd.DataFrame({'criteria': [criteria], 'score': [1000]})
|
| 151 |
+
criteria_df = pd.concat([criteria_df, new_criteria], ignore_index=True)
|
| 152 |
+
criteria_df.to_csv("criteria_df.csv")
|
| 153 |
+
criteria_df = criteria_df[["score", "criteria"]]
|
| 154 |
+
criteria_df = criteria_df.dropna()
|
| 155 |
+
return "", display_criteria_rankings(criteria_df)
|
| 156 |
+
|
| 157 |
+
def remove_criteria(criteria, criteria_df):
|
| 158 |
+
criteria = clean_string(criteria)
|
| 159 |
+
criteria_df = criteria_df[criteria_df["criteria"] != criteria]
|
| 160 |
+
return display_criteria_rankings(criteria_df)
|
| 161 |
+
|
| 162 |
+
def update_criteria_ratings_pos(first_string, second_string, criteria_df):
|
| 163 |
+
if len(criteria_df) == 0:
|
| 164 |
+
return "Add some criteria to start ranking!", "", "", display_criteria_rankings(criteria_df)
|
| 165 |
+
if first_string != "":
|
| 166 |
+
loser = criteria_df[criteria_df["criteria"] == second_string]
|
| 167 |
+
winner = criteria_df[criteria_df["criteria"] == first_string]
|
| 168 |
+
winner_score, loser_score = update_scores(winner['score'].values[0], loser['score'].values[0])
|
| 169 |
+
criteria_df.at[winner.index[0], 'score'] = winner_score
|
| 170 |
+
criteria_df.at[loser.index[0], 'score'] = loser_score
|
| 171 |
+
criteria_df = criteria_df.sort_values(by='score', ascending=False)
|
| 172 |
+
criteria_df.to_csv("criteria_df.csv")
|
| 173 |
+
return vote_startup_criteria(criteria_df)
|
| 174 |
+
|
| 175 |
+
def update_criteria_ratings_neg(first_string, second_string, criteria_df):
|
| 176 |
+
if len(criteria_df) == 0:
|
| 177 |
+
return "Add some criteria to start ranking!", "", "", display_criteria_rankings(criteria_df)
|
| 178 |
+
if first_string != "":
|
| 179 |
+
loser = criteria_df[criteria_df["criteria"] == first_string]
|
| 180 |
+
winner = criteria_df[criteria_df["criteria"] == second_string]
|
| 181 |
+
winner_score, loser_score = update_scores(winner['score'].values[0], loser['score'].values[0])
|
| 182 |
+
criteria_df.at[winner.index[0], 'score'] = winner_score
|
| 183 |
+
criteria_df.at[loser.index[0], 'score'] = loser_score
|
| 184 |
+
criteria_df = criteria_df.sort_values(by='score', ascending=False)
|
| 185 |
+
criteria_df.to_csv("criteria_df.csv")
|
| 186 |
+
return vote_startup_criteria(criteria_df)
|
| 187 |
+
|
| 188 |
+
def display_criteria_rankings(criteria_df):
|
| 189 |
+
criteria_df = criteria_df.sort_values(by='score', ascending=False)
|
| 190 |
+
criteria_df = criteria_df[["score", "criteria"]]
|
| 191 |
+
criteria_df.to_csv("criteria_df.csv")
|
| 192 |
+
return criteria_df
|
| 193 |
+
|
| 194 |
+
def calculate_overall_scores(opponents_df, criteria_df):
|
| 195 |
+
criteria_scores = criteria_df.set_index("criteria")["score"]
|
| 196 |
+
new_scores = []
|
| 197 |
+
for _, row in opponents_df.iterrows():
|
| 198 |
+
overall_score = 0
|
| 199 |
+
total_weight = 0
|
| 200 |
+
for c in criteria_df["criteria"]:
|
| 201 |
+
weight = criteria_scores[c]
|
| 202 |
+
score = row[f"{c}_score"]
|
| 203 |
+
overall_score += weight * score
|
| 204 |
+
total_weight += weight
|
| 205 |
+
# opponents_df.at[row.name, "overall_score"] = overall_score / total_weight
|
| 206 |
+
score = overall_score / total_weight
|
| 207 |
+
new_scores.append(score)
|
| 208 |
+
opponents_df["overall_score"] = new_scores
|
| 209 |
+
return opponents_df
|
| 210 |
|
| 211 |
theme = gr.themes.Soft(primary_hue="red", secondary_hue="blue")
|
| 212 |
|
| 213 |
with gr.Blocks(theme=theme) as app:
|
| 214 |
+
gr.Markdown(
|
| 215 |
+
"""## Preference-based Elo Ranker
|
| 216 |
+
This tool helps you create **accurate rankings** of things based on your personal preferences.
|
| 217 |
+
It does this by asking you questions comparing a random pair of your inputs, and then using your
|
| 218 |
+
answers to calculate Elo scores for ranking.
|
| 219 |
+
"""
|
| 220 |
+
)
|
| 221 |
with gr.Tab("Criteria Ranking"):
|
| 222 |
+
gr.Markdown(
|
| 223 |
+
"""### Rank Criteria
|
| 224 |
+
Add and rank the criteria that will be used to evaluate the opponents.
|
| 225 |
+
"""
|
| 226 |
+
)
|
| 227 |
+
with gr.Row():
|
| 228 |
+
criteria_input = gr.Textbox(label="Criteria")
|
| 229 |
+
add_criteria_button = gr.Button("Add Criteria")
|
| 230 |
+
with gr.Row():
|
| 231 |
+
remove_criteria_input = gr.Textbox(label="Criteria")
|
| 232 |
+
remove_criteria_button = gr.Button("Remove Criteria")
|
| 233 |
criteria_df = pd.DataFrame(columns=['score', 'criteria'])
|
| 234 |
criteria_rankings = gr.DataFrame(value=criteria_df, interactive=False, headers=["Score", "Criteria"])
|
| 235 |
+
with gr.Row():
|
| 236 |
+
criteria_compare_output = gr.Textbox("Add some criteria to start ranking!", label="Comparison", interactive=False)
|
| 237 |
+
with gr.Row():
|
| 238 |
+
criteria_yes_button = gr.Button("Yes", variant="secondary")
|
| 239 |
+
criteria_no_button = gr.Button("No", variant="primary")
|
| 240 |
+
with gr.Row():
|
| 241 |
+
with gr.Column():
|
| 242 |
+
criteria_compare_index_1 = gr.Textbox(label="", interactive=False, visible=False)
|
| 243 |
+
with gr.Column():
|
| 244 |
+
criteria_compare_index_2 = gr.Textbox(label="", interactive=False, visible=False)
|
| 245 |
+
criteria_new_vote = gr.Button("New Vote")
|
| 246 |
+
add_criteria_button.click(add_criteria, inputs=[criteria_input, criteria_rankings], outputs=[criteria_input, criteria_rankings])
|
| 247 |
+
remove_criteria_button.click(remove_criteria, inputs=[remove_criteria_input, criteria_rankings], outputs=criteria_rankings)
|
| 248 |
+
criteria_yes_button.click(update_criteria_ratings_pos, inputs=[criteria_compare_index_1, criteria_compare_index_2, criteria_rankings], outputs=[criteria_compare_output, criteria_compare_index_1, criteria_compare_index_2, criteria_rankings])
|
| 249 |
+
criteria_no_button.click(update_criteria_ratings_neg, inputs=[criteria_compare_index_1, criteria_compare_index_2, criteria_rankings], outputs=[criteria_compare_output, criteria_compare_index_1, criteria_compare_index_2, criteria_rankings])
|
| 250 |
+
criteria_new_vote.click(vote_startup_criteria, inputs=[criteria_rankings], outputs=[criteria_compare_output, criteria_compare_index_1, criteria_compare_index_2, criteria_rankings])
|
|
|
|
| 251 |
|
| 252 |
with gr.Tab("Opponent Ranking"):
|
| 253 |
+
with gr.Row():
|
| 254 |
+
previews_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 255 |
+
previews = gr.DataFrame(value=previews_df, interactive=False, visible=False)
|
| 256 |
+
with gr.Column():
|
| 257 |
+
gr.Markdown(
|
| 258 |
+
"""### Vote to Rank
|
| 259 |
+
"""
|
| 260 |
+
)
|
| 261 |
+
with gr.Row():
|
| 262 |
+
compare_output = gr.Textbox("Add some options to start voting!", label="Comparison", interactive=False)
|
| 263 |
+
with gr.Row():
|
| 264 |
+
yes_button = gr.Button("1", variant="secondary")
|
| 265 |
+
no_button = gr.Button("2", variant="primary")
|
| 266 |
+
with gr.Row():
|
| 267 |
+
criteria_output = gr.Textbox(label="Criteria", interactive=False)
|
| 268 |
+
new_vote = gr.Button("New Vote")
|
| 269 |
+
with gr.Row():
|
| 270 |
+
with gr.Column():
|
| 271 |
+
compare_index_1 = gr.Textbox(label="", interactive=False, visible=False)
|
| 272 |
+
with gr.Column():
|
| 273 |
+
compare_index_2 = gr.Textbox(label="", interactive=False, visible=False)
|
| 274 |
+
with gr.Column():
|
| 275 |
+
gr.Markdown(
|
| 276 |
+
"""### Rankings
|
| 277 |
+
"""
|
| 278 |
+
)
|
| 279 |
+
opponents_df = pd.DataFrame(columns=["descriptor", "opponent"] + [f"{c}_score" for c in criteria_df["criteria"]] + ["overall_score"])
|
| 280 |
+
rankings = gr.DataFrame(value=opponents_df, interactive=False, headers=["Descriptor", "Opponent"] + [f"{c} Score" for c in criteria_df["criteria"]] + ["Overall Score"])
|
| 281 |
+
|
| 282 |
+
gr.Markdown(
|
| 283 |
+
"""### Add Opponents
|
| 284 |
+
"""
|
| 285 |
+
)
|
| 286 |
+
with gr.Row():
|
| 287 |
+
descriptor_input = gr.Textbox(label="Descriptor")
|
| 288 |
+
opponent_input = gr.Textbox(label="Opponent")
|
| 289 |
+
add_button = gr.Button("Add Opponent")
|
| 290 |
+
add_button.click(add_and_compare, inputs=[descriptor_input, opponent_input, rankings, criteria_rankings], outputs=[descriptor_input, opponent_input, rankings])
|
| 291 |
+
gr.Markdown(
|
| 292 |
+
"""### Remove Opponents
|
| 293 |
+
"""
|
| 294 |
+
)
|
| 295 |
+
with gr.Row():
|
| 296 |
+
remove_descriptor_input = gr.Textbox(label="Descriptor")
|
| 297 |
+
remove_opponent_input = gr.Textbox(label="Opponent")
|
| 298 |
+
remove_button = gr.Button("Remove Opponent")
|
| 299 |
+
remove_button.click(remove_opponent, inputs=[remove_descriptor_input, remove_opponent_input, rankings], outputs=rankings)
|
| 300 |
+
|
| 301 |
+
gr.Markdown(
|
| 302 |
+
"""### Import and Export Rankings
|
| 303 |
+
"""
|
| 304 |
+
)
|
| 305 |
+
with gr.Row():
|
| 306 |
+
import_button = gr.File(label="Import CSV", file_count="single")
|
| 307 |
+
import_button.change(fn=import_csv, inputs=[import_button, rankings, criteria_rankings], outputs=[rankings])
|
| 308 |
+
with gr.Column():
|
| 309 |
+
export_link = gr.File(label="Download CSV", file_count="single")
|
| 310 |
+
export_button = gr.Button("Export as CSV")
|
| 311 |
+
export_button.click(fn=export_csv, inputs=[rankings], outputs=export_link)
|
| 312 |
+
|
| 313 |
+
gr.Markdown("### Reset Data")
|
| 314 |
+
with gr.Row():
|
| 315 |
+
reset_button = gr.Button("Reset Scores")
|
| 316 |
+
reset_button.click(reset_rankings, inputs=[rankings, criteria_rankings], outputs=rankings)
|
| 317 |
+
clear_button = gr.Button("Clear Table", variant="primary")
|
| 318 |
+
clear_button.click(clear_rankings, inputs=[rankings, criteria_rankings], outputs=rankings)
|
| 319 |
+
|
| 320 |
+
yes_button.click(update_ratings_pos, inputs=[compare_index_1, compare_index_2, criteria_output, rankings, criteria_rankings], outputs=[compare_output, compare_index_1, compare_index_2, criteria_output, rankings])
|
| 321 |
+
no_button.click(update_ratings_neg, inputs=[compare_index_1, compare_index_2, criteria_output, rankings, criteria_rankings], outputs=[compare_output, compare_index_1, compare_index_2, criteria_output, rankings])
|
| 322 |
+
new_vote.click(vote_startup_opponents, inputs=[rankings, criteria_rankings], outputs=[compare_output, compare_index_1, compare_index_2, criteria_output, rankings])
|
| 323 |
|
| 324 |
app.launch(share=False)
|