Spaces:
Runtime error
Runtime error
Merge branch 'dev-test' into 'main'
Browse filesUpdate test file
See merge request tangibleai/community/mathtext-fastapi!2
Files changed (4)
- app.py+3-2
- data/master_test_text2int.csvAdded+90
- data/test_data_text2int.csvDeleted-43
- tests/test_text2int.py+26-35
1234570 unmodified lines76777879"""FastAPI endpointTo run locally use 'uvicorn modules.app:app --host localhost --port 7860'"""from fastapi import FastAPI, Request70 unmodified linesprepare_message_data_for_logging(message_data)int_data_dict = {'type': 'integer', 'data': int_api_resp}return JSONResponse(content=int_data_dict)1234570 unmodified lines7677787980"""FastAPI endpointTo run locally use 'uvicorn app:app --host localhost --port 7860'"""from fastapi import FastAPI, Request70 unmodified linesprepare_message_data_for_logging(message_data)int_data_dict = {'type': 'integer', 'data': int_api_resp}return JSONResponse(content=int_data_dict)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990input,outputfourteen,14forteen,14one thousand four hundred ninety two,1492one thousand ninety two,1092Fourteen Hundred Ninety-Two,1492Fourteen Hundred,1400Ninety nine,99fifteen thousand five hundred-sixty,15560three hundred fifty,350one nine eight five,1985nineteen eighty-five,1985oh one,1six oh 1,601sex,6six,6eight oh,80eighty,80ate,8double eight,88eight three seven five three O nine,8375309eight three seven five three oh nine,8375309eight three seven five three zero nine,8375309eight three seven five three oh ni-ee-ine,8375309two eight,28seven oh eleven,7011seven elevens,77seven eleven,711ninety nine oh five,9905seven 0 seven 0 seven 0 seven,7070707123 hundred,1230005 o 5,50515 o 5,150515-o 5,150515 o-5,1505911-thousand,911000twenty-two twenty-two,2222twenty-two twenty-twos,484four eighty four,484four eighties,320four eighties and nine nineties,1130ninety nine hundred and seventy seven,9977seven thousands,70002 hundreds,20099 thousands and one,99001"forty-five thousand, seven hundred and nine",45709eighty eight hundred eighty,8880a hundred hundred,10000a hundred thousand,100000a hundred million,100000000nineteen ninety nine,1999forteen twenty seven,1427seventeen-thousand and seventy two,17072two hundred and nine,209two thousand ten,2010two thousand and ten,2010twelve million,120000008 billion,8000000000twenty ten,2010thirty-two hundred,3200nine,9forty two,421 2 three,123fourtean,14one tousand four hundred ninty two,1492Furteen Hundrd Ninety-Too,1492forrteen,14sevnteen-thosand and seventy two,17072ninety nine hundred ad seventy seven,9977seven thusands,70002 hunreds,20099 tousands and one,99001eighty ate hundred eighty,8880fourteen Hundred,14008 Bilion,8000000000one million three thousand one,1003001four million nine thousand seven,4009007two million five hundred thousand,2500000two tousand ten,2010two thousand teen,2010tvelve milion,12000000tventy ten,2010tirty-twoo hunred,3200sevn thoosands,7000five,5ten,10one two three and ten,12310ONE MILLion three hunded and fiv,1000305"50,500 and six",50506one_million_and_five,100000512345678910111213141516171819202122232425262728293031323334353637383940414243input,outputfourteen,14one thousand four hundred ninety two,1492Fourteen Hundred Ninety-Two,1492forteen,14seventeen-thousand and seventy two,17072two hundred and nine,209# Following are the ones that the current text2int.py fails on,-# ninety nine hundred and seventy seven,9977# seven thousands,7000# 2 hundreds,200# 99 thousands and one,9901# "forty-five thousand, seven hundred and nine",45709# eighty eight hundred eighty,8880# a hundred hundred,10000# a hundred thousand,100000# a hundred million,100000000# nineteen ninety nine,1999# forteen twenty seven,1427# one nine eight five,1985# nineteen eighty-five,1985# six,6# eighty,80# eight three seven five three zero nine,8375308# oh one,1# six oh 1,601# sex,6# eight oh,80# ate,8# double eight,88# eight three seven five three O nine,8375308# eight three seven five three oh nine,8375308# eight three seven five three 0 nine,8375308# eight three seven five three oh ni-ee-ine,8375308# two thousand ten,2010# two thousand and ten,2010# twelve million,12000000# 8 billion,8000000000# twenty ten,2010# thirty-two hundred,3200# nine,9# forty two,42# 1 2 three,123123456789101 unmodified line12131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import unittestfrom fastapi.testclient import TestClientfrom app import appTEST_DATA_FILE = "data/test_data_text2int.csv"client = TestClient(app)1 unmodified lineclass TestStringMethods(unittest.TestCase):def setUp(self):self.client = TestClient(app)def test_1(self):response = self.client.post("/text2int",json={"content": "fourteen"})self.assertEqual(response.status_code, 200)self.assertEqual(str(response.json()["message"]), "14")def test_2(self):response = self.client.post("/text2int",json={"content": "one thousand four hundred ninety two"})self.assertEqual(response.status_code, 200)self.assertEqual(str(response.json()["message"]), "1492")def test_3(self):response = self.client.post("/text2int",json={"content": "Fourteen Hundred Ninety-Two"})self.assertEqual(response.status_code, 200)self.assertEqual(str(response.json()["message"]), "1492")def test_4(self):response = client.post("/text2int",json={"content": "forteen"})self.assertEqual(response.status_code, 200)self.assertEqual(str(response.json()["message"]), "14")def test_5(self):response = client.post("/text2int",json={"content": "seventeen-thousand and seventy two"})self.assertEqual(response.status_code, 200)self.assertEqual(str(response.json()["message"]), "17072")def test_6(self):response = client.post("/text2int",json={"content": "two hundred and nine"})self.assertEqual(response.status_code, 200)self.assertEqual(str(response.json()["message"]), "209")if __name__ == '__main__':12345678910111 unmodified line131415161718192021222324252627282930313233343536373839404142434445464748495051import unittestimport pandas as pdfrom fastapi.testclient import TestClientfrom app import appTEST_DATA_FILE = "data/master_test_text2int.csv"client = TestClient(app)1 unmodified lineclass TestStringMethods(unittest.TestCase):def setUp(self):"""Creates a fastapi test client"""self.client = TestClient(app)def get_response_text2int(self, text):"""Makes a post request to the endpoint"""r = Nonetry:r = self.client.post("/text2int", json={"content": text}) \.json().get("message")except:passreturn rdef test_endpoint_text2int(self):"""Tests if endpoint is working"""response = self.client.post("/text2int",json={"content": "fourteen"})self.assertEqual(response.status_code, 200)def test_acc_score_text2int(self):"""Calculates accuracy score for endpoint"""df = pd.read_csv(TEST_DATA_FILE)df["text2int"] = df["input"].apply(func=self.get_response_text2int)df["score"] = df[["output", "text2int"]].apply(lambda row: row[0] == row[1],axis=1)df.to_csv("data/text2int_results.csv", index=False)acc_score = df["score"].mean().__round__(2)self.assertGreaterEqual(acc_score, 0.8, f"Accuracy score: '{acc_score}'. Value is too low!")if __name__ == '__main__':
app.py+3-2
data/master_test_text2int.csvAdded+90
data/test_data_text2int.csvDeleted-43
tests/test_text2int.py+26-35