tsrivallabh commited on
Commit
8145877
Β·
verified Β·
1 Parent(s): e6618d0

Synced repo using 'sync_with_huggingface' Github Action

Browse files
__pycache__/fact_checker.cpython-310.pyc CHANGED
Binary files a/__pycache__/fact_checker.cpython-310.pyc and b/__pycache__/fact_checker.cpython-310.pyc differ
 
__pycache__/fact_checker.cpython-313.pyc ADDED
Binary file (7.99 kB). View file
 
app.py CHANGED
@@ -45,7 +45,24 @@ def initialize_services():
45
  )
46
 
47
  def main():
48
- st.title("πŸ” Fact Checker")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  checker = initialize_services()
50
 
51
  # Initialize session state variables
@@ -56,74 +73,163 @@ def main():
56
  if "result" not in st.session_state:
57
  st.session_state.result = None
58
 
59
- claim = st.text_area("Enter a claim to verify:", height=150)
60
- try:
61
- df = pd.read_csv("data/pib_titles.csv")
62
- if not df.empty:
63
- sample_claims = df.sample(2)
64
- st.markdown("### πŸ§ͺ Example Claims from Dataset:")
65
- for idx, row in sample_claims.iterrows():
66
- st.markdown(f"- {row[0]}")
67
- except Exception as e:
68
- st.warning(f"Could not load example claims: {e}")
69
- confidence_threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5, 0.05)
70
-
71
- if st.button("Verify Claim"):
72
- if not claim.strip():
73
- st.error("Please enter a claim to verify")
74
- return
75
-
76
- with st.spinner("Analyzing..."):
77
- # Store result in session state
78
- st.session_state.result = checker.verify_claim(claim, confidence_threshold)
79
- st.session_state.last_claim = claim
80
- st.session_state.feedback_submitted = False # Reset feedback state for new claim
81
-
82
- # Display results from session state
83
- if st.session_state.result:
84
- result = st.session_state.result
85
- if "error" in result:
86
- st.error(f"Error: {result['error']}")
87
- if "raw_response" in result:
88
- with st.expander("Show raw LLM response"):
89
- st.code(result["raw_response"])
90
- else:
91
- # Display verdict
92
- verdict_color = {
93
- "True": "green",
94
- "False": "red",
95
- "Unverifiable": "orange"
96
- }.get(result["verdict"], "gray")
97
- st.markdown(f"**Verdict:** :{verdict_color}[{result['verdict']}]")
98
-
99
- # Display confidence score
100
- st.metric("Confidence Score", f"{result.get('confidence', 0):.2f}")
101
-
102
- # Display evidence
103
- with st.expander("View Supporting Evidence"):
104
- for idx, evidence in enumerate(result.get("evidence", []), 1):
105
- st.markdown(f"{idx}. {evidence}")
106
-
107
- # Display reasoning
108
- st.markdown("**Analysis:**")
109
- st.write(result.get("reasoning", "No reasoning provided"))
110
-
111
- # Feedback system
112
- feedback_key = f"feedback_radio_{st.session_state.last_claim}"
113
- if not st.session_state.feedback_submitted:
114
- feedback = st.radio(
115
- "Was this analysis helpful?",
116
- ["", "πŸ‘ Yes", "πŸ‘Ž No"],
117
- horizontal=True,
118
- key=feedback_key
119
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
- if feedback:
122
- store_feedback_csv(st.session_state.last_claim, result, feedback)
123
- st.session_state.feedback_submitted = True
124
- st.rerun() # Use st.rerun() instead of experimental_rerun()
125
- else:
126
- st.success("Thank you for your feedback! Your input helps improve the system.")
 
 
 
 
127
 
128
 
129
  if __name__ == "__main__":
 
45
  )
46
 
47
  def main():
48
+ # Add sticky title using HTML and CSS
49
+ st.markdown("""
50
+ <style>
51
+ .sticky-title {
52
+ position: sticky;
53
+ top: 0;
54
+ z-index: 999;
55
+ background: white;
56
+ padding-top: 1rem;
57
+ padding-bottom: 1rem;
58
+ margin-bottom: 1rem;
59
+ border-bottom: 2px solid #f0f0f0;
60
+ }
61
+ </style>
62
+ <div class="sticky-title">
63
+ <h1>πŸ” Fact Checker</h1>
64
+ </div>
65
+ """, unsafe_allow_html=True)
66
  checker = initialize_services()
67
 
68
  # Initialize session state variables
 
73
  if "result" not in st.session_state:
74
  st.session_state.result = None
75
 
76
+ # --- Custom CSS for wider columns and better visuals ---
77
+ st.markdown("""
78
+ <style>
79
+ /* Reduce max-width and remove side paddings/margins for full width */
80
+ .block-container {
81
+ padding-top: 1rem;
82
+ padding-bottom: 1rem;
83
+ max-width: 100% !important;
84
+ padding-left: 1rem !important;
85
+ padding-right: 1rem !important;
86
+ }
87
+
88
+ /* Remove default margins on main content to reduce gaps */
89
+ main > div {
90
+ margin-left: 0 !important;
91
+ margin-right: 0 !important;
92
+ }
93
+
94
+ /* Stretch columns fully */
95
+ .css-1kyxreq, .css-1r6slb0 {
96
+ width: 100% !important;
97
+ }
98
+
99
+ /* Style the DataFrame container for full width */
100
+ .stDataFrame {
101
+ background: #f9f9f9 !important;
102
+ border-radius: 12px;
103
+ border: 1px solid #e0e0e0;
104
+ padding: 0.5rem;
105
+ width: 100% !important;
106
+ }
107
+
108
+ /* Style input area */
109
+ textarea, input[type="text"] {
110
+ border: 2px solid #4CAF50 !important;
111
+ border-radius: 6px !important;
112
+ font-size: 1.1rem !important;
113
+ background: #f4f8fc !important;
114
+ width: 100% !important;
115
+ }
116
+
117
+ /* Style buttons */
118
+ button[kind="primary"] {
119
+ background: #4CAF50 !important;
120
+ color: white !important;
121
+ border-radius: 6px !important;
122
+ font-weight: bold !important;
123
+ }
124
+
125
+ /* Style scrollbars for DataFrame */
126
+ ::-webkit-scrollbar {
127
+ width: 8px;
128
+ background: #f0f0f0;
129
+ }
130
+ ::-webkit-scrollbar-thumb {
131
+ background: #bdbdbd;
132
+ border-radius: 4px;
133
+ }
134
+ </style>
135
+ """, unsafe_allow_html=True)
136
+
137
+
138
+ # --- Layout ---
139
+ spacer_col, left_col, right_col ,right_space= st.columns([1,9, 7,1], gap="large")
140
+
141
+ with left_col:
142
+ claim = st.text_area("Enter a claim to verify:", height=150)
143
+ confidence_threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5, 0.05)
144
+
145
+ if st.button("Verify Claim"):
146
+ if not claim.strip():
147
+ st.error("Please enter a claim to verify")
148
+ return
149
+
150
+ with st.spinner("Analyzing..."):
151
+ # Store result in session state
152
+ st.session_state.result = checker.verify_claim(claim, confidence_threshold)
153
+ st.session_state.last_claim = claim
154
+ st.session_state.feedback_submitted = False # Reset feedback state for new claim
155
+
156
+ # Display results from session state
157
+ if st.session_state.result:
158
+ result = st.session_state.result
159
+ if "error" in result:
160
+ st.error(f"Error: {result['error']}")
161
+ if "raw_response" in result:
162
+ with st.expander("Show raw LLM response"):
163
+ st.code(result["raw_response"])
164
+ else:
165
+ # Display verdict
166
+ verdict_color = {
167
+ "True": "green",
168
+ "False": "red",
169
+ "Unverifiable": "orange"
170
+ }.get(result["verdict"], "gray")
171
+ st.markdown(f"**Verdict:** :{verdict_color}[{result['verdict']}]")
172
+
173
+ # Display confidence score
174
+ st.metric("Confidence Score", f"{result.get('confidence', 0):.2f}")
175
+
176
+ # Display evidence
177
+ with st.expander("View Supporting Evidence"):
178
+ for idx, evidence in enumerate(result.get("evidence", []), 1):
179
+ st.markdown(f"{idx}. {evidence}")
180
+
181
+ # Display reasoning
182
+ st.markdown("**Analysis:**")
183
+ st.write(result.get("reasoning", "No reasoning provided"))
184
+
185
+ # Feedback system
186
+ feedback_key = f"feedback_radio_{st.session_state.last_claim}"
187
+ if not st.session_state.feedback_submitted:
188
+ feedback = st.radio(
189
+ "Was this analysis helpful?",
190
+ ["", "πŸ‘ Yes", "πŸ‘Ž No"],
191
+ horizontal=True,
192
+ key=feedback_key
193
+ )
194
+
195
+ if feedback:
196
+ store_feedback_csv(st.session_state.last_claim, result, feedback)
197
+ st.session_state.feedback_submitted = True
198
+ st.rerun() # Use st.rerun() instead of experimental_rerun()
199
+ else:
200
+ st.success("Thank you for your feedback! Your input helps improve the system.")
201
+
202
+ with right_col:
203
+
204
+ st.markdown("### πŸ“‹ All Claims")
205
+ try:
206
+ df = pd.read_csv("data/pib_titles.csv")["title"].to_frame()
207
+ if not df.empty:
208
+ st.markdown("""
209
+ <style>
210
+ .scrollable-cell {
211
+ overflow-x: auto;
212
+ white-space: nowrap;
213
+ max-width: 100%;
214
+ border: 1px solid #eee;
215
+ padding: 6px 8px;
216
+ font-family: monospace;
217
+ background: #fafafa;
218
+ }
219
+ </style>
220
+ """, unsafe_allow_html=True)
221
+
222
 
223
+
224
+ # Render each row as a scrollable div
225
+ for idx, row in df.iterrows():
226
+ st.markdown(
227
+ f'<div class="scrollable-cell">{row["title"]}</div>',
228
+ unsafe_allow_html=True
229
+ )
230
+ except Exception as e:
231
+ st.warning(f"Unable to display full dataset: {e}")
232
+
233
 
234
 
235
  if __name__ == "__main__":