Synced repo using 'sync_with_huggingface' Github Action
Browse files- __pycache__/fact_checker.cpython-310.pyc +0 -0
- __pycache__/fact_checker.cpython-313.pyc +0 -0
- app.py +174 -68
__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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
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 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
st.
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
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__":
|