Spaces:
Sleeping
Sleeping
Commit ·
90fcd9f
1
Parent(s): b2cd959
Add system
Browse filesFiles changed (2)
- app.py+2-2
- system/pledge_tracking.py+64-52
117 unmodified lines11811912012112112212312443 unmodified lines168169170171171172173174117 unmodified lines data = request.get_json() claim = data.get("claim", "no input") time_range_option = data.get("time_range", "month") system_start_time = datetime.now().isoformat() system_start_time = datetime.now()
suggestion_meta = data.get("suggestion_meta") pledge_date = data.get("pledge_date", "")43 unmodified lines df.to_json(json_path, orient="records", indent=2)
system_end_time = datetime.now().isoformat() system_end_time = datetime.now()
runtime = system_end_time - system_start_time
118 unmodified lines1191201211221231241251261271281291301311321231241251261271281291301311321331331341351361371381391351361371381391401411421431441451461431441451461471481491501511521531471551561481491501511581591601611521531541551561571581591601611621631641651661631641651661671681691701711721731741671681691701711721731741751761771781791801811821831841761851861781871881801811821891901911921931941951961971851981992004 unmodified lines205206207196208209210211118 unmodified lines f" 5. {questions[4]}") step_id+=1
try: augmented_tsv_file = run_augmented_searching( qa_file=qa_file_path, pledge_author=pledge_author, pledge_date=pledge_date, pipeline_base_dir=pipeline_base_dir, start_date=start_date, suggestion_meta=suggestion_meta, end_date="", )
augmented_tsv_file = run_augmented_searching( qa_file=qa_file_path, pledge_author=pledge_author, pledge_date=pledge_date, pipeline_base_dir=pipeline_base_dir, start_date=start_date, suggestion_meta=suggestion_meta, end_date="", )
with open(augmented_tsv_file, "r", encoding="utf-8") as f: line_count = sum(1 for line in f) if update_fn: update_fn(step_id, f"{line_count} URLs are retrieved") step_id+=1 with open(augmented_tsv_file, "r", encoding="utf-8") as f: line_count = sum(1 for line in f) if update_fn: update_fn(step_id, f"{line_count} URLs are retrieved") step_id+=1 except Exception as e: if update_fn: update_fn(step_id, f"❌ run_augmented_searching failed: {e}") raise
augmented_data_store_dir = os.path.join(pipeline_base_dir, "augmented_data_store") os.makedirs(augmented_data_store_dir, exist_ok=True) augmented_scraped_output_path = os.path.join(augmented_data_store_dir, "0.jsonl") run_scraper(augmented_tsv_file, augmented_scraped_output_path)
with open(augmented_scraped_output_path, "r", encoding="utf-8") as f: line_count = sum(1 for line in f if json.loads(line)["url2text"] != []) if update_fn: update_fn(step_id, f"{line_count} URL pages have been sucessefully scraped") step_id+=1
run_hero_reranking(pipeline_base_dir, suggestion_meta)
# Step 7: Preparing for GPT-4 # print("🧠 Step 7: Processing format ...") try: augmented_scraped_output_path = os.path.join(augmented_data_store_dir, "0.jsonl") run_scraper(augmented_tsv_file, augmented_scraped_output_path)
meta_data_dir = process_manifesto_data_with_metadata(input_base_dir=pipeline_base_dir)
# Step 8: Event extraction using GPT-4 print("🧠 Extracting events ...") with open(augmented_scraped_output_path, "r", encoding="utf-8") as f: line_count = sum(1 for line in f if json.loads(line)["url2text"] != []) if update_fn: update_fn(step_id, f"{line_count} URL pages have been sucessefully scraped") step_id+=1 except Exception as e: if update_fn: update_fn(step_id, f"❌ run_scraper failed: {e}") raise
try: run_hero_reranking(pipeline_base_dir, suggestion_meta)
meta_data_dir = process_manifesto_data_with_metadata(input_base_dir=pipeline_base_dir) all_info_path = os.path.join(pipeline_base_dir, "all_info_with_txt.json") unique_urls = set() with open(all_info_path, "r", encoding="utf-8") as f: for line in f: data = json.loads(line) docs = data.get("evidence", []) for doc in docs: if "url" in doc: unique_urls.add(doc["url"]) if update_fn: update_fn(step_id, f"{len(unique_urls)} documents are selected") step_id+=1 all_info_path = os.path.join(pipeline_base_dir, "all_info_with_txt.json") unique_urls = set() with open(all_info_path, "r", encoding="utf-8") as f: for line in f: data = json.loads(line) docs = data.get("evidence", []) for doc in docs: if "url" in doc: unique_urls.add(doc["url"]) if update_fn: update_fn(step_id, f"{len(unique_urls)} documents are selected") step_id+=1 except Exception as e: if update_fn: update_fn(step_id, f"❌ run_hero_reranking failed: {e}") raise try: extracted_event_path = run_gpt4_event_extraction(data_dir=pipeline_base_dir, max_tokens=100000) extracted_event_path = run_gpt4_event_extraction(data_dir=pipeline_base_dir, max_tokens=100000)
events_num = count_total_events(extracted_event_path) events_num = count_total_events(extracted_event_path)
if update_fn: update_fn(step_id, f"{events_num} events are extracted from those documents.") step_id+=1 if update_fn: update_fn(step_id, f"{events_num} events are extracted from those documents.") step_id+=1 except Exception as e: if update_fn: update_fn(step_id, f"❌ Event extraction failed: {e}") raise
# Step 9: Sorting events and label usefulness print("📅 Sorting events temporally ...")
4 unmodified lines claim=claim, suggestion_meta=suggestion_meta ) # print(sorted_events)
df = pd.DataFrame(sorted_events) sorted_event_path = f"{pipeline_base_dir}/sorted_events.xlsx" df.to_excel(sorted_event_path, index=False)app.py+2-2
system/pledge_tracking.py+64-52