Spaces:
Sleeping
Sleeping
OliverPerrin commited on
Commit ·
6d135aa
1
Parent(s): 6f4d4de
Fix type hints in demo_gradio.py for Pylance
Browse files- scripts/demo_gradio.py +11 -9
scripts/demo_gradio.py
CHANGED
|
@@ -10,25 +10,27 @@ Date: 2026-01-14
|
|
| 10 |
|
| 11 |
from __future__ import annotations
|
| 12 |
|
|
|
|
|
|
|
| 13 |
import gradio as gr
|
| 14 |
-
from datasets import load_dataset
|
| 15 |
|
| 16 |
# --------------- Load Dataset from HuggingFace Hub ---------------
|
| 17 |
|
| 18 |
print("Loading discovery dataset from HuggingFace Hub...")
|
| 19 |
-
|
| 20 |
-
print(f"Loaded {len(
|
| 21 |
|
| 22 |
-
# Convert to list for easier filtering
|
| 23 |
-
ALL_ITEMS = [dict(
|
| 24 |
|
| 25 |
# Extract unique topics and emotions
|
| 26 |
-
TOPICS = sorted(set(item["topic"] for item in ALL_ITEMS if item.get("topic")))
|
| 27 |
-
EMOTIONS = sorted(set(item["emotion"] for item in ALL_ITEMS if item.get("emotion")))
|
| 28 |
|
| 29 |
# Group by source type
|
| 30 |
-
BOOKS = [item for item in ALL_ITEMS if item.get("source_type") == "literary"]
|
| 31 |
-
PAPERS = [item for item in ALL_ITEMS if item.get("source_type") == "academic"]
|
| 32 |
|
| 33 |
print(f"Topics: {TOPICS}")
|
| 34 |
print(f"Emotions: {EMOTIONS}")
|
|
|
|
| 10 |
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
+
from typing import Any
|
| 14 |
+
|
| 15 |
import gradio as gr
|
| 16 |
+
from datasets import Dataset, load_dataset
|
| 17 |
|
| 18 |
# --------------- Load Dataset from HuggingFace Hub ---------------
|
| 19 |
|
| 20 |
print("Loading discovery dataset from HuggingFace Hub...")
|
| 21 |
+
_dataset: Dataset = load_dataset("OliverPerrin/LexiMind-Discovery", split="train") # type: ignore[assignment]
|
| 22 |
+
print(f"Loaded {len(_dataset)} items")
|
| 23 |
|
| 24 |
+
# Convert to list of dicts for easier filtering
|
| 25 |
+
ALL_ITEMS: list[dict[str, Any]] = [dict(row) for row in _dataset]
|
| 26 |
|
| 27 |
# Extract unique topics and emotions
|
| 28 |
+
TOPICS: list[str] = sorted(set(str(item["topic"]) for item in ALL_ITEMS if item.get("topic")))
|
| 29 |
+
EMOTIONS: list[str] = sorted(set(str(item["emotion"]) for item in ALL_ITEMS if item.get("emotion")))
|
| 30 |
|
| 31 |
# Group by source type
|
| 32 |
+
BOOKS: list[dict[str, Any]] = [item for item in ALL_ITEMS if item.get("source_type") == "literary"]
|
| 33 |
+
PAPERS: list[dict[str, Any]] = [item for item in ALL_ITEMS if item.get("source_type") == "academic"]
|
| 34 |
|
| 35 |
print(f"Topics: {TOPICS}")
|
| 36 |
print(f"Emotions: {EMOTIONS}")
|