Skip to content

Commit

Permalink
Merge pull request #48 from the-deep-nlp/feat/topic-generation
Browse files Browse the repository at this point in the history
send the topics along with the clustered entries in response callback;
  • Loading branch information
sudan45 authored Mar 12, 2024
2 parents 34012ba + 2030ae5 commit c4d2a53
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions analysis_module/mockserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ def process_topicmodeling(body) -> Any:
callback_url = request_body.get("callback_url")
clusters = request_body.get("max_clusters_num", 5)

labels = [
"Sudan Crisis 2022",
"Earthquake of magnitude 7.2 in 2015",
"Flood Disaster in Morocco",
"Human Trafficking in African regions"
]

try:
excerpt_ids = [x["entry_id"] for x in get_entries_data(entries_url)]
except Exception:
Expand All @@ -183,12 +190,13 @@ def process_topicmodeling(body) -> Any:

shuffle(excerpt_ids)

data = [
excerpt_ids[x:x + ceil(len(excerpt_ids) / clusters)]
for x in range(0, len(excerpt_ids), ceil(len(excerpt_ids) / clusters))
]

data = dict(enumerate(data))
data = {
idx: {
"entry_id": excerpt_ids[x:x + ceil(len(excerpt_ids) / clusters)],
"label": labels[idx] if idx < len(labels) else "Random Cluster Topic"
}
for idx, x in enumerate(range(0, len(excerpt_ids), ceil(len(excerpt_ids) / clusters)))
}

filepath = save_data_local_and_get_url(
dir_name="topicmodel", client_id=client_id, data=data
Expand Down

0 comments on commit c4d2a53

Please sign in to comment.