Spaces:
Sleeping
Sleeping
Endpoint prepared
Browse files- app.py +7 -4
- resultview.py +23 -2
- try.py +21 -0
app.py
CHANGED
|
@@ -9,13 +9,16 @@ app = FastAPI()
|
|
| 9 |
@app.post("/predict/")
|
| 10 |
async def predict(id:str):
|
| 11 |
try:
|
| 12 |
-
print("
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
except Exception as error:
|
| 17 |
return {"prediction" : error}
|
| 18 |
|
| 19 |
if __name__ =="__main__":
|
| 20 |
|
| 21 |
uvicorn.run(app,host = "0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
| 9 |
@app.post("/predict/")
|
| 10 |
async def predict(id:str):
|
| 11 |
try:
|
| 12 |
+
print("Request received")
|
| 13 |
+
tenant_json = rv.algo_start(int(id))
|
| 14 |
+
return tenant_json
|
| 15 |
+
|
| 16 |
+
|
| 17 |
except Exception as error:
|
| 18 |
return {"prediction" : error}
|
| 19 |
|
| 20 |
if __name__ =="__main__":
|
| 21 |
|
| 22 |
uvicorn.run(app,host = "0.0.0.0", port=7860)
|
| 23 |
+
|
| 24 |
+
# ASI HAREMOS LLAMADAS A LA API $ curl -X POST "https://luismidv-mlsystemtfg.hf.space/predict/?id=1"
|
resultview.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import similarity as sm
|
|
|
|
| 3 |
|
| 4 |
def tenant_visualization(similarity_matrix, requested_tenants):
|
| 5 |
#TODO VIEW COMPATIBILITY BETWEEN REQUESTED TENANTS
|
|
@@ -53,6 +54,26 @@ def algo_start(id):
|
|
| 53 |
#sm.data_checking(dataframe)
|
| 54 |
similarity_matrix = sm.encoder_matrix(dataframe, min_range = 0, max_range=100)
|
| 55 |
tenant_list = tenant_inference(similarity_matrix, id,original_dataframe)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
#tenant_visualization(similarity_matrix, [20,40,50,18,15])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import similarity as sm
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
def tenant_visualization(similarity_matrix, requested_tenants):
|
| 6 |
#TODO VIEW COMPATIBILITY BETWEEN REQUESTED TENANTS
|
|
|
|
| 54 |
#sm.data_checking(dataframe)
|
| 55 |
similarity_matrix = sm.encoder_matrix(dataframe, min_range = 0, max_range=100)
|
| 56 |
tenant_list = tenant_inference(similarity_matrix, id,original_dataframe)
|
| 57 |
+
json_convert(tenant_list)
|
|
|
|
| 58 |
#tenant_visualization(similarity_matrix, [20,40,50,18,15])
|
| 59 |
+
|
| 60 |
+
def json_convert(tenant_list):
|
| 61 |
+
#THE ALGO START FUNCTION COULD BE DOING THIS DIRECTLY, IS A POSSIBLE IMPROVEMENT IF THE WEB ISN'T WORKING FAST ENOUGH
|
| 62 |
+
|
| 63 |
+
tenants_dict = {
|
| 64 |
+
str(i) : { "Names" : " ", "Age": " ", "Smoking": " ", "Email" : " ", "Compatibility" : " "} for i in range(4)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
tenant_counter = 0
|
| 68 |
+
for tenant in tenant_list:
|
| 69 |
+
tenant_features = tenant[0]
|
| 70 |
+
tenant_compatibility = tenant[1]
|
| 71 |
+
|
| 72 |
+
for feature in tenant_features.index:
|
| 73 |
+
tenants_dict[str(tenant_counter)][feature] = str(tenant_features[feature])
|
| 74 |
+
|
| 75 |
+
tenants_dict[str(tenant_counter)]["Compatibility"] = str(tenant_compatibility)
|
| 76 |
+
tenant_counter += 1
|
| 77 |
+
|
| 78 |
+
tenants_json = json.dumps(tenants_dict, indent = 4)
|
| 79 |
+
return tenants_json
|
try.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import resultview as rv
|
| 3 |
+
import json
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
url = "https://luismidv-mlsystemtfg.hf.space/predict/"
|
| 7 |
+
params = {"id": "1"}
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|