Spaces:
Running
Running
Ali Hashhash commited on
Commit Β·
06803fa
1
Parent(s): 8a0d292
1.1
Browse files- src/api/notes_routes.py +6 -6
- src/summarization/topic_classifier.py +27 -17
src/api/notes_routes.py
CHANGED
|
@@ -305,10 +305,10 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
|
|
| 305 |
if isinstance(seg, dict) and seg.get("key_insight"):
|
| 306 |
key_points_list.append(seg["key_insight"])
|
| 307 |
|
| 308 |
-
# Step 2: Generate the
|
| 309 |
-
from src.summarization.topic_classifier import
|
| 310 |
raw_topics = summary_json.get("topics", [])
|
| 311 |
-
|
| 312 |
|
| 313 |
# Step 3: Combine everything into ONE single dictionary
|
| 314 |
note_data = {
|
|
@@ -317,7 +317,7 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
|
|
| 317 |
"videoTitle": video_title,
|
| 318 |
"notes": final_markdown,
|
| 319 |
"thumbnail": f"https://img.youtube.com/vi/{video_id}/mqdefault.jpg" if video_id else "",
|
| 320 |
-
"category":
|
| 321 |
"keyPoints": key_points_list,
|
| 322 |
"createdAt": datetime.utcnow(),
|
| 323 |
"updatedAt": datetime.utcnow(),
|
|
@@ -328,8 +328,8 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
|
|
| 328 |
# The Flutter app will perform the final save after user edits.
|
| 329 |
tasks[task_id]["status"] = "completed"
|
| 330 |
tasks[task_id]["notes"] = final_markdown
|
| 331 |
-
tasks[task_id]["topics"] =
|
| 332 |
-
tasks[task_id]["category"] =
|
| 333 |
tasks[task_id]["keyPoints"] = key_points_list
|
| 334 |
logger.info(f"β
Task {task_id} completed successfully!")
|
| 335 |
|
|
|
|
| 305 |
if isinstance(seg, dict) and seg.get("key_insight"):
|
| 306 |
key_points_list.append(seg["key_insight"])
|
| 307 |
|
| 308 |
+
# Step 2: Generate the single primary category (keep in memory)
|
| 309 |
+
from src.summarization.topic_classifier import get_primary_category
|
| 310 |
raw_topics = summary_json.get("topics", [])
|
| 311 |
+
category = get_primary_category(raw_topics) if raw_topics else "Education & Science"
|
| 312 |
|
| 313 |
# Step 3: Combine everything into ONE single dictionary
|
| 314 |
note_data = {
|
|
|
|
| 317 |
"videoTitle": video_title,
|
| 318 |
"notes": final_markdown,
|
| 319 |
"thumbnail": f"https://img.youtube.com/vi/{video_id}/mqdefault.jpg" if video_id else "",
|
| 320 |
+
"category": category,
|
| 321 |
"keyPoints": key_points_list,
|
| 322 |
"createdAt": datetime.utcnow(),
|
| 323 |
"updatedAt": datetime.utcnow(),
|
|
|
|
| 328 |
# The Flutter app will perform the final save after user edits.
|
| 329 |
tasks[task_id]["status"] = "completed"
|
| 330 |
tasks[task_id]["notes"] = final_markdown
|
| 331 |
+
tasks[task_id]["topics"] = raw_topics
|
| 332 |
+
tasks[task_id]["category"] = category
|
| 333 |
tasks[task_id]["keyPoints"] = key_points_list
|
| 334 |
logger.info(f"β
Task {task_id} completed successfully!")
|
| 335 |
|
src/summarization/topic_classifier.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
Topic Classifier β maps dynamic LLM-extracted topics to predefined UI categories.
|
| 3 |
|
| 4 |
Usage:
|
| 5 |
-
from src.summarization.topic_classifier import
|
| 6 |
|
| 7 |
topics = ["Python", "Machine Learning", "Neural Networks"]
|
| 8 |
-
result =
|
| 9 |
-
# =>
|
| 10 |
|
| 11 |
Categories:
|
| 12 |
Technology & AI | Business & Finance | Education & Science
|
|
@@ -199,22 +199,24 @@ _register("Health & Sports", [
|
|
| 199 |
# PUBLIC API
|
| 200 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 201 |
|
| 202 |
-
def
|
| 203 |
"""
|
| 204 |
-
Map a list of dynamically extracted topics to predefined UI
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
Args:
|
| 207 |
topics: List of topic strings from the LLM (e.g. ["Python", "Deep Learning"]).
|
| 208 |
|
| 209 |
Returns:
|
| 210 |
-
A
|
| 211 |
-
Falls back to ["Education & Science"] if no match is found.
|
| 212 |
|
| 213 |
Example:
|
| 214 |
-
>>>
|
| 215 |
-
|
| 216 |
-
>>>
|
| 217 |
-
|
| 218 |
"""
|
| 219 |
matched: Set[str] = set()
|
| 220 |
|
|
@@ -233,17 +235,25 @@ def classify_topics(topics: List[str]) -> List[str]:
|
|
| 233 |
break
|
| 234 |
|
| 235 |
if not matched:
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
|
| 242 |
def get_primary_category(topics: List[str]) -> str:
|
| 243 |
"""
|
| 244 |
Return the single best-matching category for the given topics.
|
| 245 |
|
| 246 |
-
|
| 247 |
"""
|
| 248 |
-
|
| 249 |
-
return categories[0] if categories else "Education & Science"
|
|
|
|
| 2 |
Topic Classifier β maps dynamic LLM-extracted topics to predefined UI categories.
|
| 3 |
|
| 4 |
Usage:
|
| 5 |
+
from src.summarization.topic_classifier import classify_topic, get_primary_category
|
| 6 |
|
| 7 |
topics = ["Python", "Machine Learning", "Neural Networks"]
|
| 8 |
+
result = classify_topic(topics)
|
| 9 |
+
# => "Technology & AI"
|
| 10 |
|
| 11 |
Categories:
|
| 12 |
Technology & AI | Business & Finance | Education & Science
|
|
|
|
| 199 |
# PUBLIC API
|
| 200 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 201 |
|
| 202 |
+
def classify_topic(topics: List[str]) -> str:
|
| 203 |
"""
|
| 204 |
+
Map a list of dynamically extracted topics to a SINGLE predefined UI category.
|
| 205 |
+
|
| 206 |
+
Returns the single best-matching category (the first match in CATEGORIES order).
|
| 207 |
+
Falls back to "Education & Science" if no match is found.
|
| 208 |
|
| 209 |
Args:
|
| 210 |
topics: List of topic strings from the LLM (e.g. ["Python", "Deep Learning"]).
|
| 211 |
|
| 212 |
Returns:
|
| 213 |
+
A single category string.
|
|
|
|
| 214 |
|
| 215 |
Example:
|
| 216 |
+
>>> classify_topic(["Python", "Machine Learning", "Neural Networks"])
|
| 217 |
+
"Technology & AI"
|
| 218 |
+
>>> classify_topic(["Investing", "AI Stocks"])
|
| 219 |
+
"Business & Finance"
|
| 220 |
"""
|
| 221 |
matched: Set[str] = set()
|
| 222 |
|
|
|
|
| 235 |
break
|
| 236 |
|
| 237 |
if not matched:
|
| 238 |
+
return "Education & Science"
|
| 239 |
+
|
| 240 |
+
# Return the first match in CATEGORIES order for consistency
|
| 241 |
+
for cat in CATEGORIES:
|
| 242 |
+
if cat in matched:
|
| 243 |
+
return cat
|
| 244 |
|
| 245 |
+
return "Education & Science"
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def classify_topics(topics: List[str]) -> List[str]:
|
| 249 |
+
"""Backward-compatible wrapper β returns a single-element list."""
|
| 250 |
+
return [classify_topic(topics)]
|
| 251 |
|
| 252 |
|
| 253 |
def get_primary_category(topics: List[str]) -> str:
|
| 254 |
"""
|
| 255 |
Return the single best-matching category for the given topics.
|
| 256 |
|
| 257 |
+
Alias for classify_topic().
|
| 258 |
"""
|
| 259 |
+
return classify_topic(topics)
|
|
|