Spaces:
Running
Running
File size: 2,777 Bytes
a962ffe 00eef23 a962ffe 00eef23 a962ffe 00eef23 2001d0c 00eef23 2001d0c 00eef23 a962ffe a2dd0df 00eef23 a2dd0df 00eef23 a2dd0df 00eef23 b616114 a2dd0df 00eef23 b616114 a104a70 b616114 a2dd0df 00eef23 a2dd0df 00eef23 a2dd0df 00eef23 8ebf5b2 00eef23 a962ffe 00eef23 |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import pandas as pd
import streamlit as st
import sqlite3
# Database setup
DB_FILE = "feedback.db"
def init_db():
# Connect to SQLite database
conn = sqlite3.connect(DB_FILE)
cursor = conn.cursor()
# Create a table for storing feedback if not exists
cursor.execute("""
CREATE TABLE IF NOT EXISTS feedback (
id INTEGER PRIMARY KEY AUTOINCREMENT,
question TEXT,
selected_answer TEXT,
rating INTEGER,
feedback_text TEXT
)
""")
conn.commit()
conn.close()
def store_feedback(question, rating, feedback_text):
conn = sqlite3.connect(DB_FILE)
cursor = conn.cursor()
cursor.execute("""
INSERT INTO feedback (question, rating, feedback_text)
VALUES (?, ?, ?)
""", (question, rating, feedback_text))
conn.commit()
conn.close()
# Initialize database
init_db()
# Load Q&A data
@st.cache_data
def load_data():
return pd.read_csv("dummy_qa_data.csv")
data = load_data()
# Session state for question navigation
if "current_index" not in st.session_state:
st.session_state.current_index = 0
# Current question index
current_index = st.session_state.current_index
# Display question and options
if 0 <= current_index < len(data):
question = data.loc[current_index, "Question"]
# answers = eval(data.loc[current_index, "Generated Answer"]) # Convert string to list of tuples
st.subheader(f"Question {current_index + 1}: {question}")
st.subheader("Generated Answer:")
st.write(data.loc[current_index, "Generated Answer"])
# selected_answer = st.radio("Choose the best answer:", options=[ans[0] for ans in answers])
# Rating
rating = st.slider("Rate the answer (1 = Worst, 5 = Best)", 1, 5, value=3)
# Free-text feedback
feedback_text = st.text_area("Any additional feedback?")
# Navigation buttons
col1, col2, col3 = st.columns([1, 1, 2])
with col1:
if st.button("Back") and current_index > 0:
st.session_state.current_index -= 1
st.experimental_rerun()
with col2:
if st.button("Next"):
# Store feedback for the current question
store_feedback(question, rating, feedback_text)
if current_index < len(data) - 1:
st.session_state.current_index += 1
st.experimental_rerun()
else:
st.success("You have completed all questions!")
st.stop()
else:
st.write("No more questions available!")
# View results for debugging (optional)
if st.checkbox("Show Feedback Database (Admin Use)"):
conn = sqlite3.connect(DB_FILE)
df = pd.read_sql_query("SELECT * FROM feedback", conn)
st.dataframe(df)
conn.close()
|