ashmib commited on
Commit
00eef23
·
verified ·
1 Parent(s): a2dd0df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -41
app.py CHANGED
@@ -1,60 +1,94 @@
1
  import pandas as pd
2
  import streamlit as st
 
3
 
4
- # Title
5
- st.title("Q&A Evaluation Tool")
6
 
7
- # Load the dataset from the repository
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- # Add columns for evaluation if not present
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
- # Display current question-answer pair
26
- idx = st.session_state.current_index
27
- if idx < len(data):
28
- st.subheader(f"Question {idx + 1}:")
29
- st.write(data.loc[idx, "Question"])
30
 
31
- st.subheader("Generated Answer:")
32
- st.write(data.loc[idx, "Generated Answer"])
 
 
33
 
34
- # Rating input
35
- rating = st.slider("Rate the answer (1 = Poor, 5 = Excellent)", 1, 5, step=1)
36
- comment = st.text_area("Add any comments or suggestions")
37
 
38
- # Save feedback
39
- if st.button("Submit Feedback"):
40
- data.at[idx, "Rating"] = rating
41
- data.at[idx, "Comments"] = comment
42
- st.session_state.current_index += 1
43
 
44
- # Save the updated dataset
45
- data.to_csv("evaluated_data.csv", index=False)
46
 
47
- # Confirmation and next question
48
- st.success("Feedback submitted!")
49
- st.experimental_rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  else:
51
- st.write("You have completed the evaluation. Thank you!")
52
-
53
- # Download the evaluated file
54
- with open("evaluated_data.csv", "rb") as f:
55
- st.download_button(
56
- "Download Evaluated Data",
57
- f,
58
- file_name="evaluated_data.csv",
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()