Spaces:
Sleeping
Sleeping
Download utils/trend_analysis.py from saurav384/Meta_ADS_SAAS: direct link, hf CLI and curl.
- Browser
- Download file 579 Bytes
-
https://huggingface.co/spaces/saurav384/Meta_ADS_SAAS/resolve/main/utils/trend_analysis.py
- Command line
-
hf download hf://spaces/saurav384/Meta_ADS_SAAS/utils/trend_analysis.py
-
curl -L -o trend_analysis.py https://huggingface.co/spaces/saurav384/Meta_ADS_SAAS/resolve/main/utils/trend_analysis.py
579 Bytes
| from collections import Counter | |
| import re | |
| def extract_keywords(texts): | |
| words = [] | |
| for t in texts: | |
| clean = re.sub(r"[^a-zA-Z ]", "", t.lower()) | |
| words.extend(clean.split()) | |
| return Counter(words) | |
| def market_trends(ads): | |
| texts = [ad["ad_creative_body"] for ad in ads] | |
| keyword_freq = extract_keywords(texts) | |
| top_keywords = [ | |
| word for word, count in keyword_freq.items() | |
| if count > 2 and len(word) > 3 | |
| ][:10] | |
| return { | |
| "total_ads": len(ads), | |
| "top_keywords": top_keywords | |
| } | |