Spaces:
Running
Running
import pandas as pd | |
import streamlit as st | |
# Title | |
st.title("Q&A Evaluation Tool") | |
# Load the dataset from the repository | |
def load_data(): | |
return pd.read_csv("dummy_qa_data.csv") | |
# Load data | |
data = load_data() | |
# 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_csv("evaluated_data.csv", 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.csv", "rb") as f: | |
st.download_button( | |
"Download Evaluated Data", | |
f, | |
file_name="evaluated_data.csv", | |
mime="text/csv", | |
) | |