Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,94 @@
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
@st.cache_data
|
9 |
def load_data():
|
10 |
return pd.read_csv("dummy_qa_data.csv")
|
11 |
|
12 |
-
# Load data
|
13 |
data = load_data()
|
14 |
|
15 |
-
#
|
16 |
-
if "Rating" not in data.columns:
|
17 |
-
data["Rating"] = ""
|
18 |
-
if "Comments" not in data.columns:
|
19 |
-
data["Comments"] = ""
|
20 |
-
|
21 |
-
# Initialize session state for tracking progress
|
22 |
if "current_index" not in st.session_state:
|
23 |
st.session_state.current_index = 0
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
if idx < len(data):
|
28 |
-
st.subheader(f"Question {idx + 1}:")
|
29 |
-
st.write(data.loc[idx, "Question"])
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
comment = st.text_area("Add any comments or suggestions")
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
data.at[idx, "Rating"] = rating
|
41 |
-
data.at[idx, "Comments"] = comment
|
42 |
-
st.session_state.current_index += 1
|
43 |
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
else:
|
51 |
-
st.write("
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
mime="text/csv",
|
60 |
-
)
|
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
+
import sqlite3
|
4 |
|
5 |
+
# Database setup
|
6 |
+
DB_FILE = "feedback.db"
|
7 |
|
8 |
+
def init_db():
|
9 |
+
# Connect to SQLite database
|
10 |
+
conn = sqlite3.connect(DB_FILE)
|
11 |
+
cursor = conn.cursor()
|
12 |
+
|
13 |
+
# Create a table for storing feedback if not exists
|
14 |
+
cursor.execute("""
|
15 |
+
CREATE TABLE IF NOT EXISTS feedback (
|
16 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
17 |
+
question TEXT,
|
18 |
+
selected_answer TEXT,
|
19 |
+
rating INTEGER,
|
20 |
+
feedback_text TEXT
|
21 |
+
)
|
22 |
+
""")
|
23 |
+
conn.commit()
|
24 |
+
conn.close()
|
25 |
+
|
26 |
+
def store_feedback(question, selected_answer, rating, feedback_text):
|
27 |
+
conn = sqlite3.connect(DB_FILE)
|
28 |
+
cursor = conn.cursor()
|
29 |
+
cursor.execute("""
|
30 |
+
INSERT INTO feedback (question, selected_answer, rating, feedback_text)
|
31 |
+
VALUES (?, ?, ?, ?)
|
32 |
+
""", (question, selected_answer, rating, feedback_text))
|
33 |
+
conn.commit()
|
34 |
+
conn.close()
|
35 |
+
|
36 |
+
# Initialize database
|
37 |
+
init_db()
|
38 |
+
|
39 |
+
# Load Q&A data
|
40 |
@st.cache_data
|
41 |
def load_data():
|
42 |
return pd.read_csv("dummy_qa_data.csv")
|
43 |
|
|
|
44 |
data = load_data()
|
45 |
|
46 |
+
# Session state for question navigation
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
if "current_index" not in st.session_state:
|
48 |
st.session_state.current_index = 0
|
49 |
|
50 |
+
# Current question index
|
51 |
+
current_index = st.session_state.current_index
|
|
|
|
|
|
|
52 |
|
53 |
+
# Display question and options
|
54 |
+
if 0 <= current_index < len(data):
|
55 |
+
question = data.loc[current_index, "Question"]
|
56 |
+
answers = eval(data.loc[current_index, "Generated Answer"]) # Convert string to list of tuples
|
57 |
|
58 |
+
st.subheader(f"Question {current_index + 1}: {question}")
|
59 |
+
selected_answer = st.radio("Choose the best answer:", options=[ans[0] for ans in answers])
|
|
|
60 |
|
61 |
+
# Rating
|
62 |
+
rating = st.slider("Rate the answer (1 = Worst, 5 = Best)", 1, 5, value=3)
|
|
|
|
|
|
|
63 |
|
64 |
+
# Free-text feedback
|
65 |
+
feedback_text = st.text_area("Any additional feedback?")
|
66 |
|
67 |
+
# Navigation buttons
|
68 |
+
col1, col2, col3 = st.columns([1, 1, 2])
|
69 |
+
|
70 |
+
with col1:
|
71 |
+
if st.button("Back") and current_index > 0:
|
72 |
+
st.session_state.current_index -= 1
|
73 |
+
st.experimental_rerun()
|
74 |
+
|
75 |
+
with col2:
|
76 |
+
if st.button("Next"):
|
77 |
+
# Store feedback for the current question
|
78 |
+
store_feedback(question, selected_answer, rating, feedback_text)
|
79 |
+
|
80 |
+
if current_index < len(data) - 1:
|
81 |
+
st.session_state.current_index += 1
|
82 |
+
st.experimental_rerun()
|
83 |
+
else:
|
84 |
+
st.success("You have completed all questions!")
|
85 |
+
st.stop()
|
86 |
else:
|
87 |
+
st.write("No more questions available!")
|
88 |
+
|
89 |
+
# View results for debugging (optional)
|
90 |
+
if st.checkbox("Show Feedback Database (Admin Use)"):
|
91 |
+
conn = sqlite3.connect(DB_FILE)
|
92 |
+
df = pd.read_sql_query("SELECT * FROM feedback", conn)
|
93 |
+
st.dataframe(df)
|
94 |
+
conn.close()
|
|
|
|