Spaces:
Sleeping
Sleeping
Commit ·
259448b
1
Parent(s): b0280c9
Add system
Browse filesFiles changed (5)
70 unmodified lines717273747576771 unmodified line7980818283848586878889909192939451 unmodified lines14614714814915015115270 unmodified linesdef calculate_time_range(option: str, pledge_date: str = None):today = datetime.today()pledge_date = datetime.strptime(pledge_date, "%Y-%m-%d")if option == "week":one_week_ago = today - timedelta(days=7)1 unmodified lineelif option == "month":one_month_ago = today - timedelta(days=30)start = max(one_month_ago, pledge_date)elif option == "year":one_year_ago = today - timedelta(days=365)start = max(one_year_ago, pledge_date)elif option == "since_pledge_date":if not pledge_date:raise ValueError("Pledge date is required for 'since_pledge_date' option")start = datetime.strptime(pledge_date, "%Y-%m-%d")else:raise ValueError("Invalid time range option")print(start)return start.strftime("%Y%m%d"), today.strftime("%Y%m%d")@app.route("/")51 unmodified linestime_start, time_end = calculate_time_range(time_range_option, pledge_date=pledge_date)print(f"[DEMO] Received claim: {claim}")print(f"[DEMO] Time range: {time_start} ~ {time_end}")print(f"[DEMO] Time range: {pledge_date}")# user_id = str(uuid.uuid4())[:8]# outputs = run_pipeline(claim, pledge_date, pledge_author, time_start, timestamp, user_id)70 unmodified lines7172737475767778798081821 unmodified line8485868788899091929394959651 unmodified lines14814915015115215315470 unmodified linesdef calculate_time_range(option: str, pledge_date: str = None):today = datetime.today()# pledge_date = datetime.strptime(pledge_date, "%Y-%m-%d")if isinstance(pledge_date, str):pledge_date = datetime.strptime(pledge_date, "%Y-%m-%d")elif not isinstance(pledge_date, datetime):raise ValueError("pledge_date must be a str or datetime")if option == "week":one_week_ago = today - timedelta(days=7)1 unmodified lineelif option == "month":one_month_ago = today - timedelta(days=30)start = max(one_month_ago, pledge_date)elif option == "since_pledge_date":if not pledge_date:raise ValueError("Pledge date is required for 'since_pledge_date' option")start = datetime.strptime(pledge_date, "%Y-%m-%d")else:raise ValueError("Invalid time range option")print(start, one_week_ago, one_month_ago, pledge_date)return start.strftime("%Y%m%d"), today.strftime("%Y%m%d")@app.route("/")51 unmodified linestime_start, time_end = calculate_time_range(time_range_option, pledge_date=pledge_date)print(f"[DEMO] Received claim: {claim}")print(f"[DEMO] Time range: {time_start} ~ {time_end}")print(f"[DEMO] Pledge date range: {pledge_date}")# user_id = str(uuid.uuid4())[:8]# outputs = run_pipeline(claim, pledge_date, pledge_author, time_start, timestamp, user_id)
56 unmodified lines575859606162636 unmodified lines707172737475768 unmodified lines8586878889909123 unmodified lines1151161171181191201214 unmodified lines12612712812913013113217 unmodified lines1501511521531541551561 unmodified line1581591601611621631648 unmodified lines17317417517617717817956 unmodified lineswith open(initial_tsv_file, "r", encoding="utf-8") as f:line_count = sum(1 for line in f)if update_fn:update_fn(step_id, f"We have found {line_count} URLs")step_id+=16 unmodified lineswith open(initial_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"We have scraped {line_count} URLs")step_id+=18 unmodified linesquestions = {line["question"] for line in json.load(f)["evidence"]}line_count = len(questions)if update_fn:update_fn(step_id, f"We have generated {line_count} search queries")step_id+=1else:23 unmodified lineswith 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"We have found {line_count} URLs")step_id+=1augmented_data_store_dir = os.path.join(pipeline_base_dir, "augmented_data_store")4 unmodified lineswith 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"We have scraped {line_count} URLs")step_id+=117 unmodified linesif "url" in doc:unique_urls.add(doc["url"])if update_fn:update_fn(step_id, f"We have found {len(unique_urls)} most relevant documents")step_id+=1extracted_event_path = run_gpt4_event_extraction(data_dir=pipeline_base_dir, max_tokens=100000)1 unmodified lineevents_num = count_total_events(extracted_event_path)if update_fn:update_fn(step_id, f"We have extracted {events_num} events from the documents.")step_id+=18 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)56 unmodified lines575859606162636 unmodified lines707172737475768 unmodified lines8586878889909123 unmodified lines1151161171181191201214 unmodified lines12612712812913013113217 unmodified lines1501511521531541551561 unmodified line1581591601611621631648 unmodified lines17317417517617717817956 unmodified lineswith open(initial_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+=16 unmodified lineswith open(initial_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+=18 unmodified linesquestions = {line["question"] for line in json.load(f)["evidence"]}line_count = len(questions)if update_fn:update_fn(step_id, f"{line_count} relevant queries are generated")step_id+=1else:23 unmodified lineswith 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")4 unmodified lineswith 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+=117 unmodified linesif "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)1 unmodified lineevents_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+=18 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)
168 unmodified lines1691701711721731741753 unmodified lines17918018118218318418539 unmodified lines225226227228229230231168 unmodified linesfile_path = os.path.join(data_dir, "gpt4_event_extraction", "gpt4o_results_0_claim.json")gpt4_results_json = load_json(file_path)print(gpt4_results_json)train_file_path = hf_hub_download(repo_id="PledgeTracker/demo_feedback",filename="train_useful.json",3 unmodified lineswith open(train_file_path, "r", encoding="utf-8") as f:train_data = json.load(f)print(train_data[0])39 unmodified linestest_instance = f"Pledge: {pledge} (Speaker: {pledge_author}; Pledge Date: {pledge_date})\nEvent Summary: {event['event']} (Event Date: {original_date})\nIs this event summary useful?"print(test_instance)label, score = gpt_eval(test_instance, train_data, instruction, suggestion_meta, ICL_id=ICL_id)168 unmodified lines1691701711721731741753 unmodified lines17918018118218318418539 unmodified lines225226227228229230231168 unmodified linesfile_path = os.path.join(data_dir, "gpt4_event_extraction", "gpt4o_results_0_claim.json")gpt4_results_json = load_json(file_path)# print(gpt4_results_json)train_file_path = hf_hub_download(repo_id="PledgeTracker/demo_feedback",filename="train_useful.json",3 unmodified lineswith open(train_file_path, "r", encoding="utf-8") as f:train_data = json.load(f)# print(train_data[0])39 unmodified linestest_instance = f"Pledge: {pledge} (Speaker: {pledge_author}; Pledge Date: {pledge_date})\nEvent Summary: {event['event']} (Event Date: {original_date})\nIs this event summary useful?"# print(test_instance)label, score = gpt_eval(test_instance, train_data, instruction, suggestion_meta, ICL_id=ICL_id)
316 unmodified lines317318319320321322323316 unmodified linesconst data = await eventsRes.json();if (!Array.isArray(data)) throw new Error("Unexpected data format");p.innerHTML = `<strong>We have found ${data.length} events for this pledge.</strong><br><br>` +data.map((e, index) => `<div class="mb-6 border-b pb-4">🗓️ <b>${e.date}</b>: ${e.event}<br>316 unmodified lines317318319320321322323324325316 unmodified linesconst data = await eventsRes.json();if (!Array.isArray(data)) throw new Error("Unexpected data format");// p.innerHTML = `<strong>We have found ${data.length} events for this pledge.</strong><br><br>` +// data.map((e, index) => `p.innerHTML =data.map((e, index) => `<div class="mb-6 border-b pb-4">🗓️ <b>${e.date}</b>: ${e.event}<br>
.DS_Store
app.py+8-6
system/pledge_tracking.py+8-8
system/process_time.py+3-3
test.html+3-1