Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import streamlit as st | |
import pandas as pd | |
def show_multi_table(p1_df, p2_df): | |
st.write("------------------") | |
p1_df = p1_df.reset_index(drop=True) | |
p2_df = p2_df.reset_index(drop=True) | |
actual_ind = 0 | |
for i in range(len(p1_df) - 1, -1, -2): # stepsize because project matchs in both ways and it should only display a match one time | |
actual_ind += 1 | |
match_df = pd.DataFrame() | |
row_from_p1 = p1_df.iloc[[i]] | |
row_from_p2 = p2_df.iloc[[i]] | |
# INTEGRATE IN PREPROCESSING !!! | |
# transform strings to list | |
try: | |
row_from_p1["crs_3_code_list"] = [row_from_p1['crs_3_code'].item().split(";")[:-1]] | |
row_from_p2["crs_3_code_list"] = [row_from_p2['crs_3_code'].item().split(";")[:-1]] | |
except: | |
row_from_p1["crs_3_code_list"] = [""] | |
row_from_p2["crs_3_code_list"] = [""] | |
try: | |
row_from_p1["crs_5_code_list"] = [row_from_p1['crs_5_code'].item().split(";")[:-1]] | |
row_from_p2["crs_5_code_list"] = [row_from_p2['crs_5_code'].item().split(";")[:-1]] | |
except: | |
row_from_p1["crs_5_code_list"] = [""] | |
row_from_p2["crs_5_code_list"] = [""] | |
row_from_p1["sdg_list"] = [row_from_p1['sgd_pred_code'].item()] | |
row_from_p2["sdg_list"] = [row_from_p2['sgd_pred_code'].item()] | |
try: | |
row_from_p1["flag"] = f"https://flagicons.lipis.dev/flags/4x3/{row_from_p1['country'].item()[:2].lower()}.svg" | |
row_from_p2["flag"] = f"https://flagicons.lipis.dev/flags/4x3/{row_from_p2['country'].item()[:2].lower()}.svg" | |
except: | |
row_from_p1["flag"] = "https://flagicons.lipis.dev/flags/4x3/xx.svg" | |
row_from_p2["flag"] = "https://flagicons.lipis.dev/flags/4x3/xx.svg" | |
#print(row_from_p1["flag"].item()) | |
# Correctly append rows to match_df | |
#st.subheader(f"#{actual_ind}") | |
#st.caption(f"Similarity: {round(row_from_p1['similarity'].item(), 4) * 100}%") | |
match_df = pd.concat([row_from_p1, row_from_p2], ignore_index=True) | |
col1, col2 = st.columns([1, 12]) | |
with col1: | |
# remove arrow from standart st.metric() | |
st.write( | |
""" | |
<style> | |
[data-testid="stMetricDelta"] svg { | |
display: none; | |
} | |
</style> | |
""", | |
unsafe_allow_html=True, | |
) | |
st.metric(label="Match", value=f"{actual_ind}", delta=f"~ {str(round(row_from_p1['similarity'].item(), 5) * 100)[:4]} %") | |
with col2: | |
st.write(" ") | |
st.dataframe( | |
match_df[["iati_id", "title_main", "orga_abbreviation", "client", "description_main", "country_name", "flag", "sdg_list", "crs_3_code_list", "crs_5_code_list"]], | |
use_container_width = True, | |
height = 35 + 35 * len(match_df), | |
column_config={ | |
"iati_id": st.column_config.TextColumn( | |
"IATI ID", | |
help="IATI Project ID", | |
disabled=True, | |
width="small" | |
), | |
"orga_abbreviation": st.column_config.TextColumn( | |
"Organization", | |
help="If description not in English, description in other language provided", | |
disabled=True, | |
width="small" | |
), | |
"client": st.column_config.TextColumn( | |
"Client", | |
help="Client organization of customer", | |
disabled=True, | |
width="small" | |
), | |
"title_main": st.column_config.TextColumn( | |
"Title", | |
help="If title not in English, title in other language provided", | |
disabled=True, | |
width="large" | |
), | |
"description_main": st.column_config.TextColumn( | |
"Description", | |
help="If description not in English, description in other language provided", | |
disabled=True, | |
width="large" | |
), | |
"country_name": st.column_config.TextColumn( | |
"Country", | |
help="Country of project", | |
disabled=True, | |
width="small" | |
), | |
"flag": st.column_config.ImageColumn( | |
"Flag", | |
help="country flag", | |
width="small" | |
), | |
"sdg_list": st.column_config.ListColumn( | |
"SDG Prediction", | |
help="Prediction of SDG's", | |
width="small" | |
), | |
"crs_3_code_list": st.column_config.ListColumn( | |
"CRS 3", | |
help="CRS 3 code given by organization", | |
width="small" | |
), | |
"crs_5_code_list": st.column_config.ListColumn( | |
"CRS 5", | |
help="CRS 5 code given by organization", | |
width="small" | |
), | |
}, | |
hide_index=True, | |
) | |
st.write("------------------") |