Spaces:
Runtime error
Runtime error
Download context_analysis_agent/utils/utils.py from subashdvorak/trygithubactions: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/subashdvorak/trygithubactions/resolve/eb40d681efb22bf63775dce2ab20bca9be635a6d/context_analysis_agent/utils/utils.py
- Command line
-
hf download hf://spaces/subashdvorak/trygithubactions@eb40d681efb22bf63775dce2ab20bca9be635a6d/context_analysis_agent/utils/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/subashdvorak/trygithubactions/resolve/eb40d681efb22bf63775dce2ab20bca9be635a6d/context_analysis_agent/utils/utils.py
1 kB
| from utils.data_loader import load_dataset | |
| import pandas as pd | |
| from utils.data_loader import load_influencer_data | |
| def save_to_db(business_details): | |
| # dataset = load_dataset("subashdvorak/tiktok-agentic-story")['train'] | |
| dataset = load_influencer_data() | |
| df = pd.DataFrame(dataset) | |
| # 2. Flatten all business detail values to a set of lowercase strings | |
| all_values = set() | |
| for v in business_details.values(): | |
| if isinstance(v, str): | |
| all_values.add(v.lower()) | |
| elif isinstance(v, list): | |
| all_values.update(map(str.lower, map(str, v))) | |
| # 3. Match rows where ANY column contains ANY of the values | |
| def row_matches(row): | |
| return any( | |
| str(cell).lower().find(val) != -1 | |
| for cell in row | |
| for val in all_values | |
| ) | |
| # 4. Apply row-wise matching | |
| matched_df = df[df.apply(row_matches, axis=1)] | |
| matched_df.to_csv('extracted_data.csv') | |
| print('Dataset updated according to business') | |