user-feedback / app.py
ashmib's picture
Create app.py
a962ffe verified
raw
history blame
2.07 kB
import pandas as pd
import streamlit as st
# Title
st.title("Q&A Evaluation Tool")
# Upload the dataset
@st.cache_data
def load_data(file_path):
return pd.read_excel(file_path)
# File upload section
uploaded_file = st.file_uploader("Upload the Q&A Excel File", type=["xlsx"])
if uploaded_file:
# Load data
data = load_data(uploaded_file)
# Add columns for evaluation if not present
if "Rating" not in data.columns:
data["Rating"] = ""
if "Comments" not in data.columns:
data["Comments"] = ""
# Initialize session state for tracking progress
if "current_index" not in st.session_state:
st.session_state.current_index = 0
# Display current question-answer pair
idx = st.session_state.current_index
if idx < len(data):
st.subheader(f"Question {idx + 1}:")
st.write(data.loc[idx, "Question"])
st.subheader("Generated Answer:")
st.write(data.loc[idx, "Generated Answer"])
# Rating input
rating = st.slider("Rate the answer (1 = Poor, 5 = Excellent)", 1, 5, step=1)
comment = st.text_area("Add any comments or suggestions")
# Save feedback
if st.button("Submit Feedback"):
data.at[idx, "Rating"] = rating
data.at[idx, "Comments"] = comment
st.session_state.current_index += 1
# Save the updated dataset
data.to_excel("evaluated_data.xlsx", index=False)
# Confirmation and next question
st.success("Feedback submitted!")
st.experimental_rerun()
else:
st.write("You have completed the evaluation. Thank you!")
# Download the evaluated file
with open("evaluated_data.xlsx", "rb") as f:
st.download_button(
"Download Evaluated Data",
f,
file_name="evaluated_data.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
else:
st.info("Please upload an Excel file to get started.")