File size: 2,067 Bytes
a962ffe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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.")