kaburia commited on
Commit
fa18fb2
·
1 Parent(s): 2657428

policy coherence model

Browse files
Files changed (4) hide show
  1. README.md +6 -6
  2. app.py +532 -0
  3. policy_evaluations.csv +108 -0
  4. requirements.txt +21 -0
README.md CHANGED
@@ -1,14 +1,14 @@
1
  ---
2
- title: Policy Coherence Annotations
3
- emoji: 😻
4
- colorFrom: blue
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 6.10.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
- short_description: Annotation tool to continuously enhance the policy coherence
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Policy Coherence Annotator
3
+ emoji: 🏃
4
+ colorFrom: red
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ short_description: Annotate policy documents for coherence
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,532 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import os
4
+ from huggingface_hub import HfApi, InferenceClient
5
+ from datasets import load_dataset
6
+ import io
7
+ import ast
8
+ import re
9
+
10
+ # --- 1. CONFIGURATION ---
11
+ DEBUG_TESTING = False
12
+ LOCAL_DATASET_PATH = "policy_evaluations.csv"
13
+ PREDICTIONS_CSV = "model_predictions.csv"
14
+
15
+ HF = 'hf'
16
+ token = 'GbeqFrdNnENcHiJtUnTKcAbVkneXrlOkHb'
17
+ HF_DATASET_REPO = "akaburia/policy-evaluations"
18
+ HF_TOKEN = HF + '_' + token
19
+
20
+ APPROVED_EMAILS = {
21
+ "kaburiaaustin1@tahmo.org": "user1",
22
+ "E.Ramos@tudelft.nl" : "user2",
23
+ "eunice.pramos@gmail.com" : "user3",
24
+ "E.Abraham@tudelft.nl" : "user4",
25
+ "dene.abv@gmail.com" : "user5",
26
+ "rafatoufofana.abv@gmail.com" : "user6",
27
+ "annorfrank@tahmo.org" : "user7",
28
+ "n.marley@tahmo.org" : "user8",
29
+ "H.F.Hagenaars@tudelft.nl" : "user9",
30
+ "kaburiaaustin1@gmail.com" : "user10"
31
+ }
32
+
33
+ DRILL_DOWN_MAP = {
34
+ "coherent": ["+3 Indivisible", "+2 Reinforcing", "+1 Enabling"],
35
+ "neutral": ["0 Consistent"],
36
+ "incoherent": ["-1 Constraining", "-2 Counteracting", "-3 Cancelling"]
37
+ }
38
+ VERIFY_CHOICES = ["neutral", "coherent", "incoherent"]
39
+
40
+ # --- NEW: LLM INITIALIZATION ---
41
+ llm_client = InferenceClient("Qwen/Qwen3-8B", token=HF_TOKEN, timeout=120)
42
+
43
+
44
+ # Pointing to the Qwen reasoning endpoint
45
+ # llm_client = InferenceClient("Qwen/Qwen3-8B", token=HF_TOKEN, timeout=60)
46
+
47
+ def generate_llm_explanation(policy_a, policy_b, prediction, exp_str):
48
+ if not exp_str or pd.isna(exp_str):
49
+ return "No attribution data available to generate a summary."
50
+
51
+ try:
52
+ raw_data = ast.literal_eval(exp_str)
53
+
54
+ # 1. Format the ENTIRE list of tokens and scores
55
+ score_list = []
56
+ for t, s in raw_data:
57
+ if isinstance(s, (int, float)):
58
+ clean_t = str(t).replace('Ġ', '').strip()
59
+ if clean_t:
60
+ score_list.append(f"'{clean_t}': {s:.3f}")
61
+
62
+ formatted_scores = ", ".join(score_list)
63
+
64
+ # 2. The Grounded Interpreter Prompt
65
+ prompt = f"""You are an expert AI auditor interpreting an Explainable AI (XAI) output.
66
+ A RoBERTa sequence classification model evaluated two policies and predicted their relationship as: {prediction.upper()}
67
+
68
+ Policy A: "{policy_a}"
69
+ Policy B: "{policy_b}"
70
+
71
+ Below is the complete Integrated Gradients feature attribution data for the sequence.
72
+ - Positive scores (> 0) mean the word acted as supporting evidence, pushing the model TOWARD the {prediction.upper()} prediction.
73
+ - Negative scores (< 0) mean the word acted as contradicting evidence, pushing the model AWAY from the prediction.
74
+ - Scores near 0.000 are neutral filler.
75
+
76
+ Token Scores:
77
+ [{formatted_scores}]
78
+
79
+ Write a highly analytical, 2 to 3 sentence explanation of the model's reasoning.
80
+ Explicitly ground your explanation in the provided text and quote the specific words that have the highest positive and highest negative scores.
81
+ Explain WHY the model saw those specific words as alignment or contradiction based on the context of the two policies. Do not hallucinate.
82
+
83
+ Auditor's Explanation:"""
84
+
85
+ # 3. Call the API (with the higher max_tokens for the reasoning block)
86
+ response = llm_client.chat_completion(
87
+ messages=[{"role": "user", "content": prompt}],
88
+ max_tokens=1500,
89
+ temperature=0.1,
90
+ top_p=0.9
91
+ )
92
+
93
+ raw_output = response.choices[0].message.content.strip()
94
+
95
+ # --- NEW: Parse and format the <think> block ---
96
+ match = re.search(r'<think>(.*?)</think>', raw_output, flags=re.DOTALL)
97
+
98
+ if match:
99
+ think_content = match.group(1).strip()
100
+ # Remove the think block from the final answer
101
+ final_answer = raw_output.replace(match.group(0), '').strip()
102
+
103
+ # Wrap the thought process in a native HTML collapsible detail tag
104
+ formatted_response = f"""
105
+ <details style="margin-bottom: 12px; padding: 10px; background-color: #f3f4f6; border-radius: 6px; border: 1px solid #e5e7eb;">
106
+ <summary style="cursor: pointer; font-weight: bold; color: #4b5563; outline: none;">🧠 Click to peek into the AI's thought process</summary>
107
+ <div style="margin-top: 10px; font-size: 0.9em; color: #6b7280; white-space: pre-wrap;">{think_content}</div>
108
+ </details>
109
+
110
+ **Final Explanation:**
111
+ {final_answer}
112
+ """
113
+ return formatted_response
114
+ else:
115
+ # Fallback just in case it doesn't generate a <think> block
116
+ return raw_output
117
+ # --- END NEW ---
118
+
119
+ except Exception as e:
120
+ print(f"LLM API Error: {e}")
121
+ return f"⚠️ Could not generate AI summary. Error: {str(e)[:60]}"
122
+
123
+
124
+ # --- 2. DATA LOADING FUNCTIONS ---
125
+ def load_data_from_hub(token):
126
+ if not token:
127
+ return None, None, "Error: Hugging Face Token is not configured."
128
+
129
+ try:
130
+ ds = load_dataset(HF_DATASET_REPO, token=token, split="train", cache_dir="./cache")
131
+ full_df = ds.to_pandas()
132
+
133
+ new_cols = ["UserVerifiedClass", "DrillDownInteraction", "AnnotatorUsername"]
134
+ for col in new_cols:
135
+ if col not in full_df.columns:
136
+ full_df[col] = pd.NA
137
+
138
+ full_df['key'] = full_df['PolicyA'].astype(str) + '||' + full_df['PolicyB'].astype(str)
139
+ pending_df = full_df[full_df['UserVerifiedClass'].isnull()].reset_index(drop=True)
140
+
141
+ status = f"Loaded {len(pending_df)} remaining items to annotate. ({len(full_df) - len(pending_df)} already complete) [LIVE: HF Hub]"
142
+ return full_df, pending_df, status
143
+
144
+ except Exception as e:
145
+ return None, None, f"Error loading dataset from Hub: {e}"
146
+
147
+ def load_data_from_local():
148
+ try:
149
+ if not os.path.exists(LOCAL_DATASET_PATH):
150
+ if not os.path.exists(PREDICTIONS_CSV):
151
+ return None, None, f"Error: '{PREDICTIONS_CSV}' not found. Please run batch_inference.py first."
152
+
153
+ df = pd.read_csv(PREDICTIONS_CSV)
154
+ if "model_label" not in df.columns:
155
+ return None, None, f"Error: '{PREDICTIONS_CSV}' is missing 'model_label' column."
156
+
157
+ df["UserVerifiedClass"] = pd.NA
158
+ df["DrillDownInteraction"] = pd.NA
159
+ df["AnnotatorUsername"] = pd.NA
160
+ df.to_csv(LOCAL_DATASET_PATH, index=False)
161
+
162
+ full_df = pd.read_csv(LOCAL_DATASET_PATH)
163
+ new_cols = ["UserVerifiedClass", "DrillDownInteraction", "AnnotatorUsername"]
164
+ for col in new_cols:
165
+ if col not in full_df.columns:
166
+ full_df[col] = pd.NA
167
+
168
+ full_df['key'] = full_df['PolicyA'].astype(str) + '||' + full_df['PolicyB'].astype(str)
169
+ pending_df = full_df[full_df['UserVerifiedClass'].isnull()].reset_index(drop=True)
170
+
171
+ status = f"Loaded {len(pending_df)} remaining items to annotate. [DEBUG: Local CSV]"
172
+ return full_df, pending_df, status
173
+ except Exception as e:
174
+ return None, None, f"Error loading local dataset: {e}"
175
+
176
+ # --- 3. DATA SAVING FUNCTIONS ---
177
+ def save_annotation_to_hub(index, verified_class, drill_down, user_tag, token, full_df, pending_df):
178
+ if not drill_down: return {status_box: "Error: Please select a drill-down interaction."}
179
+ if not user_tag: return {status_box: "Error: User tag is missing. Please re-login."}
180
+ try:
181
+ current_key = pending_df.loc[index, 'key']
182
+ full_df.loc[full_df['key'] == current_key, 'UserVerifiedClass'] = verified_class
183
+ full_df.loc[full_df['key'] == current_key, 'DrillDownInteraction'] = drill_down
184
+ full_df.loc[full_df['key'] == current_key, 'AnnotatorUsername'] = user_tag
185
+
186
+ csv_buffer = io.StringIO()
187
+ full_df.drop(columns=['key']).to_csv(csv_buffer, index=False)
188
+ csv_content_bytes = csv_buffer.getvalue().encode('utf-8')
189
+
190
+ api = HfApi()
191
+ api.upload_file(
192
+ path_or_fileobj=io.BytesIO(csv_content_bytes),
193
+ path_in_repo="policy_evaluations.csv",
194
+ repo_id=HF_DATASET_REPO,
195
+ token=token,
196
+ repo_type="dataset"
197
+ )
198
+
199
+ save_status = f"Saved to Hub: {verified_class} | {drill_down} by {user_tag}"
200
+ ui_updates = load_next_item(pending_df, index + 1)
201
+ ui_updates[status_box] = save_status
202
+ ui_updates[full_df_state] = full_df
203
+ return ui_updates
204
+ except Exception as e:
205
+ return {status_box: f"Error saving to Hub: {e}"}
206
+
207
+ def save_annotation_to_local(index, verified_class, drill_down, user_tag, full_df, pending_df):
208
+ if not drill_down: return {status_box: "Error: Please select a drill-down interaction."}
209
+ if not user_tag: return {status_box: "Error: User tag is missing. Please re-login."}
210
+ try:
211
+ current_key = pending_df.loc[index, 'key']
212
+ full_df.loc[full_df['key'] == current_key, 'UserVerifiedClass'] = verified_class
213
+ full_df.loc[full_df['key'] == current_key, 'DrillDownInteraction'] = drill_down
214
+ full_df.loc[full_df['key'] == current_key, 'AnnotatorUsername'] = user_tag
215
+
216
+ full_df.drop(columns=['key']).to_csv(LOCAL_DATASET_PATH, index=False)
217
+ save_status = f"Saved (Local): {verified_class} | {drill_down} by {user_tag}"
218
+ ui_updates = load_next_item(pending_df, index + 1)
219
+ ui_updates[status_box] = save_status
220
+ ui_updates[full_df_state] = full_df
221
+ return ui_updates
222
+ except Exception as e:
223
+ return {status_box: f"Error saving locally: {e}"}
224
+
225
+ # --- 4. CUSTOM HTML GENERATOR ---
226
+ def generate_heatmap_html(raw_data, policy_a_text):
227
+ if not raw_data or not isinstance(raw_data, list):
228
+ return "<i>No explainability data found for this row.</i>"
229
+
230
+ try:
231
+ scores = [abs(s) for t, s in raw_data if isinstance(s, (int, float))]
232
+ max_abs = max(scores) if scores else 0.001
233
+
234
+ target_length = len(str(policy_a_text).replace(" ", "").strip())
235
+ current_length = 0
236
+ split_index = len(raw_data) - 1
237
+
238
+ for i, (token, score) in enumerate(raw_data):
239
+ clean_t = str(token).replace('Ġ', '').replace(' ', '')
240
+ current_length += len(clean_t)
241
+ if current_length >= target_length - 2:
242
+ split_index = i
243
+ break
244
+
245
+ policy_a_data = raw_data[:split_index + 1]
246
+ policy_b_data = raw_data[split_index + 1:]
247
+
248
+ def render_block(data_subset, title):
249
+ block_html = f"""
250
+ <div style='flex: 1; padding: 16px; background: #ffffff; border-radius: 8px; border: 1px solid #e5e7eb; box-shadow: 0 1px 2px rgba(0,0,0,0.05);'>
251
+ <h4 style='margin-top: 0; margin-bottom: 12px; color: #4b5563; font-family: sans-serif; border-bottom: 1px solid #e5e7eb; padding-bottom: 8px;'>{title}</h4>
252
+ <div style='line-height: 2.2; font-size: 15px; font-family: sans-serif; white-space: pre-wrap;'>
253
+ """
254
+
255
+ for token, score in data_subset:
256
+ if not isinstance(score, (int, float)): continue
257
+ alpha = min(abs(score) / max_abs, 1.0)
258
+
259
+ if score > 0: bg_color = f"rgba(16, 185, 129, {alpha})"
260
+ else: bg_color = f"rgba(239, 68, 68, {alpha})"
261
+
262
+ if abs(score) < 0.02: bg_color = "transparent"
263
+
264
+ clean_token = str(token)
265
+ margin_left = "0px"
266
+
267
+ if clean_token.startswith(' ') or clean_token.startswith('Ġ'):
268
+ clean_token = clean_token[1:]
269
+ margin_left = "4px"
270
+
271
+ span = f"<span title='Score: {score:.4f}' style='background-color: {bg_color}; border-radius: 3px; padding: 2px 0px; margin-left: {margin_left}; display: inline-block;'>{clean_token}</span>"
272
+ block_html += span
273
+
274
+ block_html += "</div></div>"
275
+ return block_html
276
+
277
+ html_str = f"""
278
+ <div style='margin-bottom: 15px; font-family: sans-serif;'>
279
+ <div style='display: flex; justify-content: space-between; width: 100%; max-width: 450px; font-size: 12px; font-weight: bold; color: #4b5563; margin-bottom: 4px;'>
280
+ <span>Strong Negative (-)</span>
281
+ <span>Neutral</span>
282
+ <span>Strong Positive (+)</span>
283
+ </div>
284
+ <div style='display: flex; align-items: center; width: 100%; max-width: 450px; height: 14px; background: linear-gradient(to right, rgba(239, 68, 68, 1), rgba(255,255,255,0), rgba(16, 185, 129, 1)); border-radius: 4px; border: 1px solid #d1d5db;'></div>
285
+ </div>
286
+
287
+ <div style='display: flex; gap: 20px;'>
288
+ {render_block(policy_a_data, 'Policy A Impact')}
289
+ {render_block(policy_b_data, 'Policy B Impact')}
290
+ </div>
291
+ """
292
+ return html_str
293
+ except Exception as e:
294
+ print(f"Error generating HTML: {e}")
295
+ return "<i>Error rendering heatmap.</i>"
296
+
297
+ # --- 5. GRADIO UI ---
298
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
299
+ gr.Markdown("# Policy Coherence Annotation Tool")
300
+ gr.Markdown(
301
+ """
302
+ Welcome! This tool is for human-in-the-loop annotation.
303
+ 1. Log in with your authorized email.
304
+ 2. The model's prediction for two policies will be shown.
305
+ 3. **Step 1:** Verify if the model's 3-class prediction is correct, or change it.
306
+ 4. **Step 2:** Select a 7-class drill-down label.
307
+ 5. Click 'Save & Next'. If you are unsure, you can click 'Skip & Next'.
308
+ """
309
+ )
310
+
311
+ full_df_state = gr.State()
312
+ pending_df_state = gr.State()
313
+ current_index_state = gr.State(value=0)
314
+ hf_token_state = gr.State()
315
+ user_tag_state = gr.State()
316
+
317
+ with gr.Group() as login_box:
318
+ with gr.Row():
319
+ email_box = gr.Textbox(label="Email", placeholder="Enter your authorized email...")
320
+ login_btn = gr.Button("Login & Load Dataset", variant="primary")
321
+ progress_bar = gr.Markdown(value="Waiting for login...")
322
+
323
+ with gr.Group(visible=False) as annotation_box:
324
+ with gr.Row():
325
+ with gr.Group():
326
+ gr.Markdown("### 📄 Policy / Objective A")
327
+ policy_a_display = gr.Textbox(show_label=False, interactive=False, lines=4, container=False)
328
+ with gr.Group():
329
+ gr.Markdown("### 📄 Policy / Objective B")
330
+ policy_b_display = gr.Textbox(show_label=False, interactive=False, lines=4, container=False)
331
+
332
+ gr.Markdown("### 🔍 Model Reasoning (Explainability Heatmap)")
333
+ gr.Markdown("This shows the sequential flow of the text. Subwords are stitched back together for readability. **Hover your mouse over any word to see its exact mathematical impact score.**")
334
+
335
+ explanation_display = gr.HTML(label="Token Attributions")
336
+
337
+ # --- NEW: AI Summary Accordion ---
338
+ with gr.Accordion("🤖 Click to view AI-Generated Summary", open=False) as ai_accordion:
339
+ generate_ai_btn = gr.Button("✨ Ask AI to Summarize Reasoning", size="sm")
340
+ ai_summary_display = gr.Markdown("Click the button above to generate a summary of the model's reasoning.")
341
+ gr.Markdown("---")
342
+ # --- END NEW ---
343
+
344
+ with gr.Row():
345
+ model_confidence_label = gr.Label(label="Model Confidence")
346
+ user_verified_radio = gr.Radio(
347
+ label="Step 1: Verify/Correct Classification",
348
+ choices=VERIFY_CHOICES,
349
+ info="The model's prediction is selected by default."
350
+ )
351
+
352
+ user_drill_down_dropdown = gr.Dropdown(
353
+ label="Step 2: Drill-Down Interaction",
354
+ choices=[],
355
+ interactive=True
356
+ )
357
+
358
+ with gr.Row():
359
+ skip_btn = gr.Button("Skip & Next (Unsure)")
360
+ save_btn = gr.Button("Save & Next", variant="primary")
361
+
362
+ status_box = gr.Textbox(label="Status", interactive=False)
363
+
364
+ # --- 6. UI Event Handlers ---
365
+
366
+ # --- NEW: LLM Trigger Function ---
367
+ def fetch_ai_summary(index, pending_df):
368
+ if pending_df is None or index >= len(pending_df):
369
+ return "No data available."
370
+ row = pending_df.iloc[index]
371
+ return generate_llm_explanation(
372
+ policy_a=row["PolicyA"],
373
+ policy_b=row["PolicyB"],
374
+ prediction=row["model_label"],
375
+ exp_str=row.get("explanation_data")
376
+ )
377
+
378
+ generate_ai_btn.click(
379
+ fn=fetch_ai_summary,
380
+ inputs=[current_index_state, pending_df_state],
381
+ outputs=[ai_summary_display]
382
+ )
383
+ # --- END NEW ---
384
+
385
+ def update_drill_down_choices(verified_class):
386
+ choices = DRILL_DOWN_MAP.get(verified_class, [])
387
+ value = choices[0] if len(choices) == 1 else None
388
+ return gr.Dropdown(choices=choices, value=value, interactive=len(choices) > 1)
389
+
390
+ def load_next_item(pending_df, index):
391
+ if pending_df is None: return {status_box: "Data not loaded."}
392
+
393
+ total_items = len(pending_df)
394
+ if index >= total_items:
395
+ return {
396
+ progress_bar: gr.Markdown(f"**Annotation Complete! ({total_items} items total)**"),
397
+ policy_a_display: "All items annotated.",
398
+ policy_b_display: "",
399
+ explanation_display: "<div>Done.</div>",
400
+ annotation_box: gr.Group(visible=False)
401
+ }
402
+
403
+ row = pending_df.iloc[index]
404
+ model_pred = row["model_label"]
405
+
406
+ if "model_confidence" in row:
407
+ confidence = row["model_confidence"]
408
+ conf_dict = {}
409
+ remaining_prob = (1.0 - confidence) / 2.0
410
+ for l in VERIFY_CHOICES:
411
+ if l == model_pred: conf_dict[l] = confidence
412
+ else: conf_dict[l] = remaining_prob
413
+ else:
414
+ conf_dict = {
415
+ "neutral": row.get("Confidence_Neutral", 0.0),
416
+ "coherent": row.get("Confidence_Coherent", 0.0),
417
+ "incoherent": row.get("Confidence_Incoherent", 0.0)
418
+ }
419
+
420
+ drill_down_choices = DRILL_DOWN_MAP.get(model_pred, [])
421
+ drill_down_value = drill_down_choices[0] if len(drill_down_choices) == 1 else None
422
+ drill_down_interactive = len(drill_down_choices) > 1
423
+
424
+ html_output = "<i>No explainability data found for this row.</i>"
425
+ exp_str = row.get("explanation_data")
426
+
427
+ if pd.notna(exp_str) and isinstance(exp_str, str) and exp_str.strip() != "":
428
+ try:
429
+ raw_data = ast.literal_eval(exp_str)
430
+ html_output = generate_heatmap_html(raw_data, row["PolicyA"])
431
+ except Exception as e:
432
+ print(f"Failed to parse explanation string using ast: {e}")
433
+ html_output = "<i>Error parsing explanation data for this row.</i>"
434
+
435
+ return {
436
+ progress_bar: gr.Markdown(f"**Annotating Item {index + 1} of {total_items}**"),
437
+ policy_a_display: row["PolicyA"],
438
+ policy_b_display: row["PolicyB"],
439
+ explanation_display: html_output,
440
+ model_confidence_label: conf_dict,
441
+ user_verified_radio: model_pred,
442
+ user_drill_down_dropdown: gr.Dropdown(choices=drill_down_choices, value=drill_down_value, interactive=drill_down_interactive),
443
+ current_index_state: index,
444
+ # --- NEW: Reset AI outputs on Next ---
445
+ ai_summary_display: "Click the button above to generate a summary of the model's reasoning.",
446
+ ai_accordion: gr.Accordion(open=False),
447
+ # --- END NEW ---
448
+ annotation_box: gr.Group(visible=True)
449
+ }
450
+
451
+ def login_and_load(email):
452
+ if email not in APPROVED_EMAILS:
453
+ return {progress_bar: gr.Markdown(f"<font color='red'>Error: Email '{email}' is not authorized.</font>"), login_box: gr.Group(visible=True)}
454
+
455
+ user_tag = APPROVED_EMAILS[email]
456
+
457
+ if DEBUG_TESTING:
458
+ full_df, pending_df, status = load_data_from_local()
459
+ token_to_store = "debug_mode"
460
+ else:
461
+ if not HF_TOKEN:
462
+ return {progress_bar: gr.Markdown(f"<font color='red'>Error: HF_TOKEN is missing.</font>"), login_box: gr.Group(visible=True)}
463
+ full_df, pending_df, status = load_data_from_hub(HF_TOKEN)
464
+ token_to_store = HF_TOKEN
465
+
466
+ if full_df is None: return {progress_bar: gr.Markdown(f"<font color='red'>{status}</font>"), login_box: gr.Group(visible=True)}
467
+
468
+ first_item_updates = load_next_item(pending_df, 0)
469
+ first_item_updates[full_df_state] = full_df
470
+ first_item_updates[pending_df_state] = pending_df
471
+ first_item_updates[progress_bar] = f"Login successful as **{user_tag}**. {status}"
472
+ first_item_updates[hf_token_state] = token_to_store
473
+ first_item_updates[user_tag_state] = user_tag
474
+ first_item_updates[login_box] = gr.Group(visible=False)
475
+ first_item_updates[annotation_box] = gr.Group(visible=True)
476
+ return first_item_updates
477
+
478
+ login_btn.click(
479
+ fn=login_and_load,
480
+ inputs=[email_box],
481
+ # --- NEW: Ensure new outputs are caught ---
482
+ outputs=[
483
+ progress_bar, policy_a_display, policy_b_display, explanation_display,
484
+ model_confidence_label, user_verified_radio, user_drill_down_dropdown,
485
+ current_index_state, annotation_box, login_box,
486
+ full_df_state, pending_df_state, hf_token_state, user_tag_state, status_box,
487
+ ai_summary_display, ai_accordion
488
+ ]
489
+ )
490
+
491
+ def save_wrapper(index, verified_class, drill_down, user_tag, token, full_df, pending_df):
492
+ if DEBUG_TESTING: return save_annotation_to_local(index, verified_class, drill_down, user_tag, full_df, pending_df)
493
+ else: return save_annotation_to_hub(index, verified_class, drill_down, user_tag, token, full_df, pending_df)
494
+
495
+ def skip_item(index, pending_df):
496
+ ui_updates = load_next_item(pending_df, index + 1)
497
+ ui_updates[status_box] = f"Skipped item {index + 1}."
498
+ return ui_updates
499
+
500
+ skip_btn.click(
501
+ fn=skip_item,
502
+ inputs=[current_index_state, pending_df_state],
503
+ outputs=[
504
+ progress_bar, policy_a_display, policy_b_display, explanation_display,
505
+ model_confidence_label, user_verified_radio, user_drill_down_dropdown,
506
+ current_index_state, annotation_box, status_box,
507
+ ai_summary_display, ai_accordion
508
+ ]
509
+ )
510
+
511
+ user_verified_radio.change(
512
+ fn=update_drill_down_choices,
513
+ inputs=user_verified_radio,
514
+ outputs=user_drill_down_dropdown
515
+ )
516
+
517
+ save_btn.click(
518
+ fn=save_wrapper,
519
+ inputs=[
520
+ current_index_state, user_verified_radio, user_drill_down_dropdown,
521
+ user_tag_state, hf_token_state, full_df_state, pending_df_state
522
+ ],
523
+ outputs=[
524
+ progress_bar, policy_a_display, policy_b_display, explanation_display,
525
+ model_confidence_label, user_verified_radio, user_drill_down_dropdown,
526
+ current_index_state, annotation_box, status_box, full_df_state,
527
+ ai_summary_display, ai_accordion
528
+ ]
529
+ )
530
+
531
+ if __name__ == "__main__":
532
+ demo.launch(debug=True)
policy_evaluations.csv ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ PolicyA,PolicyB,model_label,model_confidence
2
+ "Prioritize consolidation of land for crops, livestock and fisheries use.", ,neutral,0.9997270703315736
3
+ "Identify, map, and regulate zones for agricultural practices in terms of type of resource, systems, climatic and ecological diversities.",Develop and implement a national water body classification system and register.,coherent,0.9983433485031128
4
+ Provide for establishment of agricultural model centers of excellence and ensure they are efficiently utilized and maintained for the initial intended purpose., ,neutral,0.9996975660324096
5
+ Legislate on appropriate land sizes suitable for various agricultural enterprises including conservancies based on ecological zones and economic potential., ,neutral,0.9997099041938782
6
+ "Develop mechanisms for control, management, and use of alien and invasive species.",Integrate implementation of catchment and ecosystem management into irrigation projects and other water storage investments,coherent,0.9987309575080872
7
+ Promote establishment of common settlements to ease pressure on agricultural land., ,neutral,0.9997181296348572
8
+ Provide for rural and urban land use strategies to assist communities achieve optimum productivity and make rural land use planning an integral part of land adjudication processes., ,neutral,0.9997003078460692
9
+ Encourage landowners growing cash crops to reserve a portion of their land for food production., ,neutral,0.9996978044509888
10
+ Prioritize implementation of provisions that provide for at least 10% tree cover on any agricultural land holding., ,neutral,0.99972265958786
11
+ "Conserve water catchments and riparian zones to ensure regular supply of water for development of crops, livestock, and fisheries resources.",Put in place and implement the water Resource Quality Objectives (RQOs) for the various categories of water resources.,coherent,0.9986172914505004
12
+ "Promote organic farming for sustainable crops, livestock, and fisheries production.","Mainstream climate change in the water sector to safeguard the sector from adverse effects of climate change by promoting adaptation and mitigation actions at national, basin and county levels.",coherent,0.9987714886665344
13
+ "Prioritize consolidation of land for crops, livestock and fisheries use.","Provide linkages with provisions of the National Land Policy, which provide a framework for access, planning, utilization, and administration of land in the country",incoherent,0.998067319393158
14
+ "Identify, map, and regulate zones for agricultural practices in terms of type of resource, systems, climatic and ecological diversities.","Collaborate with other stakeholders to ensure efficient use of land resource for biomass, food production and other human needs",coherent,0.9985039234161376
15
+ Provide for establishment of agricultural model centers of excellence and ensure they are efficiently utilized and maintained for the initial intended purpose., ,neutral,0.9996975660324096
16
+ Legislate on appropriate land sizes suitable for various agricultural enterprises including conservancies based on ecological zones and economic potential., ,neutral,0.9997099041938782
17
+ "Develop mechanisms for control, management, and use of alien and invasive species.",The government to establish a coordinated approach for the management of water reservoirs.,coherent,0.9986935257911682
18
+ Promote establishment of common settlements to ease pressure on agricultural land., ,neutral,0.9997181296348572
19
+ Provide for rural and urban land use strategies to assist communities achieve optimum productivity and make rural land use planning an integral part of land adjudication processes., ,neutral,0.9997003078460692
20
+ Encourage landowners growing cash crops to reserve a portion of their land for food production., ,neutral,0.9996978044509888
21
+ Prioritize implementation of provisions that provide for at least 10% tree cover on any agricultural land holding., ,neutral,0.99972265958786
22
+ "Conserve water catchments and riparian zones to ensure regular supply of water for development of crops, livestock, and fisheries resources.",Develop a framework for coordination for use of water resource against various interests,incoherent,0.998171329498291
23
+ "Promote organic farming for sustainable crops, livestock, and fisheries production.", ,neutral,0.9997133612632751
24
+ "Prioritize consolidation of land for crops, livestock and fisheries use.",Prioritize land use for climate change mitigation activities.,incoherent,0.6960943937301636
25
+ "Identify, map, and regulate zones for agricultural practices in terms of type of resource, systems, climatic and ecological diversities.","Identify, map, and document all land uses in the country to be put in an inventory that is updated every 5 years for urban and 10 years for rural.",coherent,0.9981333613395692
26
+ Provide for establishment of agricultural model centers of excellence and ensure they are efficiently utilized and maintained for the initial intended purpose., ,neutral,0.9996975660324096
27
+ Legislate on appropriate land sizes suitable for various agricultural enterprises including conservancies based on ecological zones and economic potential.,Enforce the constitutional requirement on minimum and maximum land holding acreages and institute mechanisms for land adjustment programs.,coherent,0.9988558292388916
28
+ "Develop mechanisms for control, management, and use of alien and invasive species.",Enforce application of land use guidelines on Biodiversity and Invasive Species.,coherent,0.9986571073532104
29
+ Promote establishment of common settlements to ease pressure on agricultural land., ,neutral,0.9997181296348572
30
+ Provide for rural and urban land use strategies to assist communities achieve optimum productivity and make rural land use planning an integral part of land adjudication processes.,All lands should be managed according to their actual suitability and local land use plans will be required to implement proper management.,coherent,0.9985671043395996
31
+ Encourage landowners growing cash crops to reserve a portion of their land for food production.,Promote high value commercial agriculture.,incoherent,0.998073935508728
32
+ Prioritize implementation of provisions that provide for at least 10% tree cover on any agricultural land holding.,Develop a framework for incentives to encourage achievement of a minimum 10% forest cover at county level.,coherent,0.998689353466034
33
+ "Conserve water catchments and riparian zones to ensure regular supply of water for development of crops, livestock, and fisheries resources.", ,neutral,0.9997116923332214
34
+ "Promote organic farming for sustainable crops, livestock, and fisheries production.", ,neutral,0.9997133612632751
35
+ "Prioritize consolidation of land for crops, livestock and fisheries use.", ,neutral,0.9997270703315736
36
+ "Identify, map, and regulate zones for agricultural practices in terms of type of resource, systems, climatic and ecological diversities.", ,neutral,0.9996883869171144
37
+ Provide for establishment of agricultural model centers of excellence and ensure they are efficiently utilized and maintained for the initial intended purpose.,Promote and enhance best practices for optimal and sustainable land use.,coherent,0.9985764026641846
38
+ Legislate on appropriate land sizes suitable for various agricultural enterprises including conservancies based on ecological zones and economic potential., ,neutral,0.9997099041938782
39
+ "Develop mechanisms for control, management, and use of alien and invasive species.","Develop and implement a strategy to contain, control and mitigate alien and invasive species.",coherent,0.998664140701294
40
+ Promote establishment of common settlements to ease pressure on agricultural land., ,neutral,0.9997181296348572
41
+ Provide for rural and urban land use strategies to assist communities achieve optimum productivity and make rural land use planning an integral part of land adjudication processes.,Develop and enforce integrated land use planning at all levels.,coherent,0.9986701011657716
42
+ Encourage landowners growing cash crops to reserve a portion of their land for food production., ,neutral,0.9996978044509888
43
+ Prioritize implementation of provisions that provide for at least 10% tree cover on any agricultural land holding.,Formulate strategies to increase tree cover,coherent,0.9984756112098694
44
+ "Conserve water catchments and riparian zones to ensure regular supply of water for development of crops, livestock, and fisheries resources.",Ensure all water catchment areas are zoned and managed as protected areas and free from excision.,coherent,0.9984276294708252
45
+ "Promote organic farming for sustainable crops, livestock, and fisheries production.",Promote and support eco and organic farming so as to maintain soil fertility,incoherent,0.9980952143669128
46
+ "Ensure that water resources, wetlands, riparian and catchment areas are well mapped, protected, rehabilitated, conserved and managed, by all levels of government.",Identify and map out water catchment areas boundaries and gazette them as protected areas.,coherent,0.9984933137893676
47
+ "Coordinate with relevant regulatory authorities, at national and county government level, to implement sustainable water resource management interventions into land use, physical planning and development control systems.",The government to establish a coordinated approach for the management of water reservoirs.,coherent,0.9984790682792664
48
+ "Ensure that the allocation of water abstraction rights observes equity, giving priority to domestic uses, and the ecological reserve in order to stay within sustainable limits.",Develop a framework for coordination for use of water resource against various interests,incoherent,0.998027503490448
49
+ Develop and implement a national water body classification system and register., ,neutral,0.9996873140335084
50
+ "Establish a national system for acquisition, management and sharing of water resources information and data for continuous and coordinated surveillance, assessment and monitoring of basin areas, aquifers, and water bodies.","Invest in hydrological data collection, management and dissemination",coherent,0.9988512992858888
51
+ Put in place and implement the water Resource Quality Objectives (RQOs) for the various categories of water resources., ,neutral,0.9996649026870728
52
+ Integrate implementation of catchment and ecosystem management into irrigation projects and other water storage investments, ,neutral,0.9997186064720154
53
+ "Mainstream climate change in the water sector to safeguard the sector from adverse effects of climate change by promoting adaptation and mitigation actions at national, basin and county levels.",Support the development and implementation of the national policy on climate change,coherent,0.9982386827468872
54
+ "Develop national and county water master plans for water harvesting and storage, water supply and sanitation water investments, including last mile connections for water security.",The Government shall implement hydro power projects as multi-purpose projects.,coherent,0.9988009929656982
55
+ "Ensure that water resources, wetlands, riparian and catchment areas are well mapped, protected, rehabilitated, conserved, and managed, by all levels of government.","Protected areas such as habitat for endangered biodiversity, ecologically sensitive sites, national heritage, water towers, marine waters, wetlands forests and sites with fossils fuels and energy resources will not be allocated for private use or de-gazetted.",coherent,0.998695194721222
56
+ "Coordinate with relevant regulatory authorities, at national and county government level, to implement sustainable water resource management interventions into land use, physical planning and development control systems.","Identify, map, and document all land uses in the country to be put in an inventory that is updated every 5 years for urban and 10 years for rural.",coherent,0.9982775449752808
57
+ "Ensure that the allocation of water abstraction rights observes equity, giving priority to domestic uses, and the ecological reserve in order to stay within sustainable limits.",Zone and protect lands appropriate for agricultural uses.,incoherent,0.9981064796447754
58
+ Develop and implement a national water body classification system and register., ,neutral,0.9996873140335084
59
+ "Establish a national system for acquisition, management and sharing of water resources information and data for continuous and coordinated surveillance, assessment and monitoring of basin areas, aquifers, and water bodies.", ,neutral,0.9997047781944276
60
+ Put in place and implement the water Resource Quality Objectives (RQOs) for the various categories of water resources., ,neutral,0.9996649026870728
61
+ Integrate implementation of catchment and ecosystem management into irrigation projects and other water storage investments,Enforce application of land use guidelines on Biodiversity and Invasive Species.,coherent,0.9986531734466552
62
+ "Mainstream climate change in the water sector to safeguard the sector from adverse effects of climate change by promoting adaptation and mitigation actions at national, basin and county levels.",Prioritize land use for climate change mitigation activities.,coherent,0.998798370361328
63
+ "Develop national and county water master plans for water harvesting and storage, water supply and sanitation water investments, including last mile connections for water security.", ,neutral,0.9997026324272156
64
+ "Ensure that water resources, wetlands, riparian and catchment areas are well mapped, protected, rehabilitated, conserved and managed, by all levels of government.","Ensure the protection of wetlands, riverbanks, hilltops, and slopes from unsustainable practices to prevent soil erosion and environmental degradation.",coherent,0.9311214089393616
65
+ "Coordinate with relevant regulatory authorities, at national and county government level, to implement sustainable water resource management interventions into land use, physical planning, and development control systems.",Harmonise and coordinate the roles of various regulatory agencies charged with the management of fr eshwater and wetland ecosystems.,coherent,0.9985670447349548
66
+ "Ensure that the allocation of water abstraction rights observes equity, giving priority to domestic uses, and the ecological reserve to stay within sustainable limits.", ,neutral,0.9997207522392272
67
+ Develop and implement a national water body classification system and register.,Ensure all water catchment areas are zoned and managed as protected areas and free from excision,coherent,0.9983522891998292
68
+ "Establish a national system for acquisition, management and sharing of water resources information and data for continuous and coordinated surveillance, assessment and monitoring of basin areas, aquifers, and water bodies.", ,neutral,0.9997047781944276
69
+ Put in place and implement the water Resource Quality Objectives (RQOs) for the various categories of water resources.,Improve the management and conservation of water supply sources,coherent,0.998686134815216
70
+ Integrate implementation of catchment and ecosystem management into irrigation projects and other water storage investments,"Develop and implement a strategy to contain, control and mitigate alien and invasive species.",coherent,0.9985812902450562
71
+ "Mainstream climate change in the water sector to safeguard the sector from adverse effects of climate change by promoting adaptation and mitigation actions at national, basin and county levels.","Strengthen capacity for national and county level institutions to support national climate resilience, low carbon development through integrating climate change into implementation strategies.",coherent,0.9986571073532104
72
+ "Develop national and county water master plans for water harvesting and storage, water supply and sanitation water investments, including last mile connections for water security.",Develop and implement integrated freshwater and wetland resources management strategies and action plans.,coherent,0.9985104203224182
73
+ The government to establish a coordinated approach for the management of water reservoirs., ,neutral,0.9997020363807678
74
+ Develop a framework for coordination for use of water resource against various interests, ,neutral,0.9997090697288512
75
+ Identify and map out water catchment areas boundaries and gazette them as protected areas.,"Protected areas such as habitat for endangered biodiversity, ecologically sensitive sites, national heritage, water towers, marine waters, wetlands forests and sites with fossils fuels and energy resources will not be allocated for private use or de-gazetted.",coherent,0.9986095428466796
76
+ The Government shall implement hydro power projects as multi-purpose projects., ,neutral,0.9997033476829528
77
+ The government to invest in increased storage capacity for hydro power reservoirs, ,neutral,0.9997135996818542
78
+ "Invest in hydrological data collection, management and dissemination", ,neutral,0.9997149109840392
79
+ Provide incentives to promote the local production and use of efficient solar systems., ,neutral,0.9997019171714784
80
+ "Provide a framework for connection of electricity generated from solar energy to national and isolated grids, through direct sale or net metering.", ,neutral,0.9996978044509888
81
+ "Provide linkages with provisions of the National Land Policy, which provide a framework for access, planning, utilization and administration of land in the country","Identify, map, and document all land uses in the country to be put in an inventory that is updated every 5 years for urban and 10 years for rural.",coherent,0.9983162879943848
82
+ Support the development and implementation of the national policy on climate change,Prioritize land use for climate change mitigation activities.,coherent,0.9986888766288756
83
+ "Collaborate with other stakeholders to ensure efficient use of land resource for biomass, food production and other human needs",All lands should be managed according to their actual suitability and local land use plans will be required to implement proper management.,coherent,0.998324692249298
84
+ The government to establish a coordinated approach for the management of water reservoirs.,Harmonise and coordinate the roles of various regulatory agencies charged with the management of freshwater and wetland ecosystems.,coherent,0.9985480904579164
85
+ Develop a framework for coordination for use of water resource against various interests, ,neutral,0.9997090697288512
86
+ Identify and map out water catchment areas boundaries and gazette them as protected areas.,Ensure all water catchment areas are zoned and managed as protected areas and free from excision,coherent,0.9986754059791564
87
+ The Government shall implement hydro power projects as multi-purpose projects., ,neutral,0.9997033476829528
88
+ The government to invest in increased storage capacity for hydro power reservoirs,"Ensure the protection of wetlands, riverbanks, hilltops, and slopes from unsustainable practices to prevent soil erosion and environmental degradation.",incoherent,0.9979775547981262
89
+ "Invest in hydrological data collection, management and dissemination", ,neutral,0.9997149109840392
90
+ Provide incentives to promote the local production and use of efficient solar systems., ,neutral,0.9997019171714784
91
+ "Provide a framework for connection of electricity generated from solar energy to national and isolated grids, through direct sale or net metering.", ,neutral,0.9996978044509888
92
+ "Provide linkages with provisions of the National Land Policy, which provide a framework for access, planning, utilization and administration of land in the country",Develop and enforce integrated land use planning at all levels.,coherent,0.9986265897750854
93
+ Support the development and implementation of the national policy on climate change,"Strengthen capacity for national and county level institutions to support national climate resilience, low carbon development through integrating climate change into implementation strategies.",coherent,0.9984599351882936
94
+ "Collaborate with other stakeholders to ensure efficient use of land resource for biomass, food production and other human needs",Promote and enhance best practices for optimal and sustainable land use.,coherent,0.9983749389648438
95
+ All lands should be managed according to their actual suitability and local land use plans will be required to implement proper management.,Develop and enforce integrated land use planning at all levels.,coherent,0.9984402060508728
96
+ Promote high value commercial agriculture.,Promote and support eco and organic farming so as to maintain soil fertility,incoherent,0.99810129404068
97
+ Enforce the constitutional requirement on minimum and maximum land holding acreages and institute mechanisms for land adjustment programs., ,neutral,0.9997013211250304
98
+ "Protected areas such as habitat for endangered biodiversity, ecologically sensitive sites, national heritage, water towers, marine waters, wetlands forests and sites with fossils fuels and energy resources will not be allocated for private use or de-gazetted.",Ensure all water catchment areas are zoned and managed as protected areas and free from excision,coherent,0.9987078905105592
99
+ "Identify, map, and document all land uses in the country to be put in an inventory that is updated every 5 years for urban and 10 years for rural.", ,neutral,0.99965238571167
100
+ Develop a framework for incentives to encourage achievement of a minimum 10% forest cover at county level.,Formulate strategies to increase tree cover,coherent,0.9985941052436828
101
+ Discourage open access to grazing land among the pastoralists by promoting development of communal grazing management plans., ,neutral,0.9997197985649108
102
+ Make provision for the possibility of exclusion of cropping and overstocking on lands currently under management where public disbenefit is arising and compensate producers affected by exclusion orders that extinguish or reduce existing rights to produce on that land.,"Ensure the protection of wetlands, riverbanks, hilltops, and slopes from unsustainable practices to prevent soil erosion and environmental degradation.",coherent,0.9696201086044312
103
+ Prohibit settlement and other activities within sensitive ecological zones., ,neutral,0.999710500240326
104
+ "Identify and map each major habitat type and ensure that where more than 80% of the original extent of a particular habitat has been lost nationally that no further loss is permitted, and that restoration is undertaken to reach a minimum 20% target.",Maintain all gazetted protected areas and reclaim and restore the encroached parks and reserves for enhanced wildlife conservation.,coherent,0.9986227750778198
105
+ Prioritize land use for climate change mitigation activities., ,neutral,0.9997233748435974
106
+ Zone and protect lands appropriate for agricultural uses., ,neutral,0.9997249245643616
107
+ "Develop and implement a regulatory framework for reclamation, rehabilitation, restoration, and use of reclaimed land.", ,neutral,0.9997076392173768
108
+ Enforce application of land use guidelines on Biodiversity and Invasive Species.,"Develop and implement a strategy to contain, control and mitigate alien and invasive species.",coherent,0.99832946062088
requirements.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ huggingface_hub
2
+ gradio
3
+ transformers>=4.40.0
4
+ # langchain>=0.1.14
5
+ # sentence-transformers>=2.5.1
6
+ # faiss-cpu>=1.7.4
7
+ # torch>=2.1.0
8
+ # langchain-community>=0.0.30
9
+ # gradio-client==1.11.0
10
+ # pydantic==2.10.6
11
+ numpy
12
+ pandas
13
+ requests
14
+ datasets
15
+ # boto3
16
+ # rank-bm25
17
+ # pypdf
18
+ # Pillow
19
+ # pytesseract
20
+ # openai
21
+