tejastake's picture
Update app.py
31baee4 verified
import numpy as np
import streamlit as st
import pandas as pd
from sklearn.metrics import ndcg_score
st.title("NDCG Score Calculator")
st.sidebar.write('Params:')
k = st.sidebar.text_input('k value', key='k')
tr_value = st.text_input('Enter Single Value for true_relevance', key='tr_value')
uploaded_file = st.file_uploader("Upload your CSV or Excel file", type=['csv', 'xlsx'])
limit_num = st.text_input('Enter Limit for Records:', key='limit_num')
if uploaded_file is not None and tr_value and k and limit_num:
if uploaded_file.name.endswith('.csv'):
df = pd.read_csv(uploaded_file)
elif uploaded_file.name.endswith('.xlsx'):
df = pd.read_excel(uploaded_file)
#pnkc_values = df['PNKC'].tolist()
scores = df['pred_score'].tolist()
scores_lst = scores[:int(limit_num)]
st.write(f'Considering First {limit_num}')
true_relevance = []
for x in range(int(limit_num)):
true_relevance.append(int(tr_value.strip()))
true_relevance_arr = np.asarray([true_relevance])
scores_arr = np.asarray([scores_lst])
if st.button('Get_Result:'):
ndcg_scr = ndcg_score(true_relevance_arr, scores_arr, k=int(k))
st.write('NDCG Score:')
st.write(ndcg_scr)
else:
st.warning('Please enter values for true_relevance and k.')