Modify API
This commit is contained in:
parent
99aacdc440
commit
07f2aa12e3
144
main.py
144
main.py
@ -14,16 +14,10 @@ app = FastAPI()
|
|||||||
|
|
||||||
|
|
||||||
class Data(BaseModel):
|
class Data(BaseModel):
|
||||||
challenge: str
|
metric: str
|
||||||
dev_expected: str = ""
|
file_expected: str = ""
|
||||||
dev_out: str = ""
|
file_out: str = ""
|
||||||
testA_expected: str = ""
|
file_in: str = ""
|
||||||
testA_out: str = ""
|
|
||||||
testB_expected: str = ""
|
|
||||||
testB_out: str = ""
|
|
||||||
dev_in: str= ""
|
|
||||||
testA_in: str=""
|
|
||||||
testB_in: str=""
|
|
||||||
|
|
||||||
|
|
||||||
def preprocess_data(out, expected):
|
def preprocess_data(out, expected):
|
||||||
@ -61,15 +55,11 @@ def get_answerability_f1(trues, preds):
|
|||||||
return answerability_f1
|
return answerability_f1
|
||||||
|
|
||||||
|
|
||||||
def get_scores(trues, preds):
|
def get_final_score(trues, preds):
|
||||||
scores = {}
|
scores = {}
|
||||||
scores["Levenshtein"] = get_levenshtein_score(trues, preds)
|
scores["Levenshtein"] = get_levenshtein_score(trues, preds)
|
||||||
scores["AnswerabilityF1"] = get_answerability_f1(trues, preds)
|
scores["AnswerabilityF1"] = get_answerability_f1(trues, preds)
|
||||||
scores["Final"] = round((scores["Levenshtein"] + scores["AnswerabilityF1"]) / 2, 2)
|
return round((scores["Levenshtein"] + scores["AnswerabilityF1"]) / 2, 2)
|
||||||
|
|
||||||
scores["Levenshtein"] = round(get_levenshtein_score(trues, preds), 2)
|
|
||||||
scores["AnswerabilityF1"] = round(get_answerability_f1(trues, preds), 2)
|
|
||||||
return scores
|
|
||||||
|
|
||||||
|
|
||||||
def get_emotion_recognition_scores(df_in, df_expected, df_predition):
|
def get_emotion_recognition_scores(df_in, df_expected, df_predition):
|
||||||
@ -107,71 +97,79 @@ def get_emotion_recognition_scores(df_in, df_expected, df_predition):
|
|||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root(data: Data):
|
async def root(data: Data):
|
||||||
challenge = data.challenge
|
metric = data.metric
|
||||||
dev_expected = data.dev_expected
|
file_expected = data.file_expected
|
||||||
dev_out = data.dev_out
|
file_out = data.file_out
|
||||||
testA_expected = data.testA_expected
|
file_in = data.file_in
|
||||||
testA_out = data.testA_out
|
|
||||||
testB_expected = data.testB_expected
|
|
||||||
testB_out = data.testB_out
|
|
||||||
dev_in = data.dev_in
|
|
||||||
testA_in = data.testA_in
|
|
||||||
testB_in = data.testB_in
|
|
||||||
|
|
||||||
if challenge == "QuestionAnswering":
|
try:
|
||||||
results = {}
|
if metric == "Final":
|
||||||
if len(dev_out) > 0:
|
if len(file_out) > 0:
|
||||||
dev_out, dev_expected = preprocess_data(dev_out, dev_expected)
|
file_out, file_expected = preprocess_data(file_out, file_expected)
|
||||||
if len(dev_out) != len(dev_expected):
|
if len(file_out) != len(file_expected):
|
||||||
return ERROR_RESPONSE
|
return ERROR_RESPONSE
|
||||||
results["dev-0"] = get_scores(dev_expected, dev_out)
|
|
||||||
|
|
||||||
if len(testA_out) > 0:
|
|
||||||
testA_out, testA_expected = preprocess_data(testA_out, testA_expected)
|
|
||||||
if len(testA_out) != len(testA_expected):
|
|
||||||
return ERROR_RESPONSE
|
|
||||||
results["test-A"] = get_scores(testA_expected, testA_out)
|
|
||||||
|
|
||||||
if len(testB_out) > 0:
|
|
||||||
testB_out, testB_expected = preprocess_data(testB_out, testB_expected)
|
|
||||||
if len(testB_out) != len(testB_expected):
|
|
||||||
return ERROR_RESPONSE
|
|
||||||
results["test-B"] = get_scores(testB_expected, testB_out)
|
|
||||||
|
|
||||||
if len(results) == 0:
|
|
||||||
return ERROR_RESPONSE
|
|
||||||
else:
|
|
||||||
return {
|
return {
|
||||||
"status": 200,
|
"status": 200,
|
||||||
"results": results
|
"result": get_final_score(file_expected, file_out)
|
||||||
}
|
}
|
||||||
elif challenge == "EmotionRecognition":
|
elif metric == "Levenshtein":
|
||||||
results = {}
|
if len(file_out) > 0:
|
||||||
if len(dev_out) > 0:
|
file_out, file_expected = preprocess_data(file_out, file_expected)
|
||||||
df_in = pd.read_table(io.StringIO(dev_in))
|
if len(file_out) != len(file_expected):
|
||||||
df_expected = pd.read_table(io.StringIO(dev_expected))
|
|
||||||
df_predition = pd.read_table(io.StringIO(dev_out))
|
|
||||||
|
|
||||||
results["dev-0"] = get_emotion_recognition_scores(df_in, df_expected, df_predition)
|
|
||||||
if len(testA_out) > 0:
|
|
||||||
df_in = pd.read_table(io.StringIO(testA_in))
|
|
||||||
df_expected = pd.read_table(io.StringIO(testA_expected))
|
|
||||||
df_predition = pd.read_table(io.StringIO(testA_out))
|
|
||||||
|
|
||||||
results["test-A"] = get_emotion_recognition_scores(df_in, df_expected, df_predition)
|
|
||||||
if len(testB_out) > 0:
|
|
||||||
df_in = pd.read_table(io.StringIO(testB_in))
|
|
||||||
df_expected = pd.read_table(io.StringIO(testB_expected))
|
|
||||||
df_predition = pd.read_table(io.StringIO(testB_out))
|
|
||||||
|
|
||||||
results["test-B"] = get_emotion_recognition_scores(df_in, df_expected, df_predition)
|
|
||||||
|
|
||||||
if len(results) == 0:
|
|
||||||
return ERROR_RESPONSE
|
return ERROR_RESPONSE
|
||||||
else:
|
|
||||||
return {
|
return {
|
||||||
"status": 200,
|
"status": 200,
|
||||||
"results": results
|
"result": round(get_levenshtein_score(file_expected, file_out), 2)
|
||||||
}
|
}
|
||||||
else:
|
elif metric == "AnswerabilityF1":
|
||||||
|
if len(file_out) > 0:
|
||||||
|
file_out, file_expected = preprocess_data(file_out, file_expected)
|
||||||
|
if len(file_out) != len(file_expected):
|
||||||
|
return ERROR_RESPONSE
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": 200,
|
||||||
|
"result": round(get_answerability_f1(file_expected, file_out), 2)
|
||||||
|
}
|
||||||
|
elif metric == "FinalF1":
|
||||||
|
if len(file_out) > 0:
|
||||||
|
df_in = pd.read_table(io.StringIO(file_in))
|
||||||
|
df_expected = pd.read_table(io.StringIO(file_expected))
|
||||||
|
df_predition = pd.read_table(io.StringIO(file_out))
|
||||||
|
|
||||||
|
results = get_emotion_recognition_scores(df_in, df_expected, df_predition)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": 200,
|
||||||
|
"result": results["FinalF1"]
|
||||||
|
}
|
||||||
|
elif metric == "SentenceF1":
|
||||||
|
if len(file_out) > 0:
|
||||||
|
df_in = pd.read_table(io.StringIO(file_in))
|
||||||
|
df_expected = pd.read_table(io.StringIO(file_expected))
|
||||||
|
df_predition = pd.read_table(io.StringIO(file_out))
|
||||||
|
|
||||||
|
results = get_emotion_recognition_scores(df_in, df_expected, df_predition)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": 200,
|
||||||
|
"result": results["SentenceF1"]
|
||||||
|
}
|
||||||
|
elif metric == "TextF1":
|
||||||
|
if len(file_out) > 0:
|
||||||
|
df_in = pd.read_table(io.StringIO(file_in))
|
||||||
|
df_expected = pd.read_table(io.StringIO(file_expected))
|
||||||
|
df_predition = pd.read_table(io.StringIO(file_out))
|
||||||
|
|
||||||
|
results = get_emotion_recognition_scores(df_in, df_expected, df_predition)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": 200,
|
||||||
|
"result": results["TextF1"]
|
||||||
|
}
|
||||||
|
except:
|
||||||
|
return ERROR_RESPONSE
|
||||||
|
|
||||||
return ERROR_RESPONSE
|
return ERROR_RESPONSE
|
Loading…
Reference in New Issue
Block a user