Spaces:
Running
Running
Update Data_Fetching_and_Rendering.py
Browse files
Data_Fetching_and_Rendering.py
CHANGED
@@ -7,6 +7,7 @@ from transformers import pipeline
|
|
7 |
|
8 |
from sessions import create_session
|
9 |
from error_handling import display_error
|
|
|
10 |
|
11 |
import logging
|
12 |
|
@@ -131,6 +132,9 @@ def fetch_posts_and_stats(comm_client_id, community_token, count=10):
|
|
131 |
post_urns = [p["id"] for p in raw_posts if ":share:" in p["id"] or ":ugcPost:" in p["id"]]
|
132 |
stats_map = {}
|
133 |
|
|
|
|
|
|
|
134 |
for i in range(0, len(post_urns), 20):
|
135 |
batch = post_urns[i:i+20]
|
136 |
params = {'q': 'organizationalEntity', 'organizationalEntity': org_urn}
|
@@ -177,6 +181,9 @@ def fetch_posts_and_stats(comm_client_id, community_token, count=10):
|
|
177 |
})
|
178 |
logging.info(f"Appended post data for {post_id}: Likes={likes}, Comments={comments_count}, Shares={shares}, Clicks={clicks}")
|
179 |
|
|
|
|
|
|
|
180 |
|
181 |
return posts, org_name, sentiments
|
182 |
|
|
|
7 |
|
8 |
from sessions import create_session
|
9 |
from error_handling import display_error
|
10 |
+
from posts_categorization import batch_summarize_and_classify
|
11 |
|
12 |
import logging
|
13 |
|
|
|
132 |
post_urns = [p["id"] for p in raw_posts if ":share:" in p["id"] or ":ugcPost:" in p["id"]]
|
133 |
stats_map = {}
|
134 |
|
135 |
+
post_texts = [{"text": p["commentary"] or p.get("specificContent", {}).get("com.linkedin.ugc.ShareContent", {}).get("shareCommentaryV2", {}).get("text", "")} for p in raw_posts]
|
136 |
+
structured_results = batch_summarize_and_classify(post_texts)
|
137 |
+
|
138 |
for i in range(0, len(post_urns), 20):
|
139 |
batch = post_urns[i:i+20]
|
140 |
params = {'q': 'organizationalEntity', 'organizationalEntity': org_urn}
|
|
|
181 |
})
|
182 |
logging.info(f"Appended post data for {post_id}: Likes={likes}, Comments={comments_count}, Shares={shares}, Clicks={clicks}")
|
183 |
|
184 |
+
for post, structured in zip(posts, structured_results):
|
185 |
+
post["summary"] = structured["summary"]
|
186 |
+
post["category"] = structured["category"]
|
187 |
|
188 |
return posts, org_name, sentiments
|
189 |
|