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 lines11811912012112212312443 unmodified lines168169170171172173174117 unmodified linesdata = request.get_json()claim = data.get("claim", "no input")time_range_option = data.get("time_range", "month")system_start_time = datetime.now().isoformat()suggestion_meta = data.get("suggestion_meta")pledge_date = data.get("pledge_date", "")43 unmodified linesdf.to_json(json_path, orient="records", indent=2)system_end_time = datetime.now().isoformat()runtime = system_end_time - system_start_time117 unmodified lines11811912012112212312443 unmodified lines168169170171172173174117 unmodified linesdata = request.get_json()claim = data.get("claim", "no input")time_range_option = data.get("time_range", "month")system_start_time = datetime.now()suggestion_meta = data.get("suggestion_meta")pledge_date = data.get("pledge_date", "")43 unmodified linesdf.to_json(json_path, orient="records", indent=2)system_end_time = datetime.now()runtime = system_end_time - system_start_time
118 unmodified lines1191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871884 unmodified lines193194195196197198199118 unmodified linesf" 5. {questions[4]}")step_id+=1augmented_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+=1augmented_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+=1run_hero_reranking(pipeline_base_dir, suggestion_meta)# Step 7: Preparing for GPT-4# print("π§ Step 7: Processing format ...")meta_data_dir = process_manifesto_data_with_metadata(input_base_dir=pipeline_base_dir)# Step 8: Event extraction using GPT-4print("π§ Extracting events ...")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+=1extracted_event_path = run_gpt4_event_extraction(data_dir=pipeline_base_dir, max_tokens=100000)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# Step 9: Sorting events and label usefulnessprint("π Sorting events temporally ...")4 unmodified linesclaim=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)118 unmodified lines1191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992004 unmodified lines205206207208209210211118 unmodified linesf" 5. {questions[4]}")step_id+=1try: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+=1except Exception as e:if update_fn:update_fn(step_id, f"β run_augmented_searching failed: {e}")raiseaugmented_data_store_dir = os.path.join(pipeline_base_dir, "augmented_data_store")os.makedirs(augmented_data_store_dir, exist_ok=True)try: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+=1except Exception as e:if update_fn:update_fn(step_id, f"β run_scraper failed: {e}")raisetry: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+=1except Exception as e:if update_fn:update_fn(step_id, f"β run_hero_reranking failed: {e}")raisetry:extracted_event_path = run_gpt4_event_extraction(data_dir=pipeline_base_dir, max_tokens=100000)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+=1except Exception as e:if update_fn:update_fn(step_id, f"β Event extraction failed: {e}")raiseprint("π Sorting events temporally ...")4 unmodified linesclaim=claim,suggestion_meta=suggestion_meta)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