Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import lru_cache
|
2 |
+
from typing import Dict, List
|
3 |
+
|
4 |
+
import plotly.express as px
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
from datasets import Dataset, get_dataset_infos, load_dataset
|
8 |
+
|
9 |
+
BASE_DATASET: str = "lion-ai/pl_med_data"
|
10 |
+
|
11 |
+
dataset_names_map: Dict[str, str] = {
|
12 |
+
"znany_lekarz": "Porady - pytania i odpowiedzi",
|
13 |
+
"kor_epikryzy_qa": "Dokumentacja medyczna - pytania i odpowiedzi",
|
14 |
+
"wikipedia": "Ogólna wiedza medyczna - pytania i opowiedzi",
|
15 |
+
}
|
16 |
+
|
17 |
+
reverse_dataset_names_map: Dict[str, str] = {v: k for k, v in dataset_names_map.items()}
|
18 |
+
|
19 |
+
|
20 |
+
@st.cache_resource
|
21 |
+
def list_datasets() -> Dict[str, Dataset]:
|
22 |
+
"""
|
23 |
+
Retrieves a list of dataset information.
|
24 |
+
|
25 |
+
Returns:
|
26 |
+
List[Dict[str, str]]: A list of dataset information.
|
27 |
+
"""
|
28 |
+
return get_dataset_infos(BASE_DATASET)
|
29 |
+
|
30 |
+
|
31 |
+
def show_examples(dataset_name: str, split: str) -> None:
|
32 |
+
dataset_name = reverse_dataset_names_map.get(dataset_name, dataset_name)
|
33 |
+
|
34 |
+
dataset: Dataset = load_dataset(BASE_DATASET, dataset_name, split=f"{split}[:10]")
|
35 |
+
st.data_editor(dataset.to_pandas(), use_container_width=True)
|
36 |
+
|
37 |
+
|
38 |
+
def count_all_examples(datasets: Dict[str, Dataset]) -> None:
|
39 |
+
count: int = 0
|
40 |
+
for dataset_name, dataset_info in datasets.items():
|
41 |
+
count += dataset_info.num_examples
|
42 |
+
st.metric(label="Total no. of instructions", value=f"{count:,}")
|
43 |
+
|
44 |
+
|
45 |
+
def filter_splits(dataset: Dict[str, Dataset], split: str) -> Dict[str, Dataset]:
|
46 |
+
"""
|
47 |
+
Filter the dataset based on the specified split.
|
48 |
+
|
49 |
+
Args:
|
50 |
+
dataset (Dict[str, Dataset]): A dictionary containing dataset information.
|
51 |
+
split (str): The split to filter the dataset by.
|
52 |
+
|
53 |
+
Returns:
|
54 |
+
Dict[str, Dataset]: A dictionary containing the filtered dataset splits.
|
55 |
+
"""
|
56 |
+
|
57 |
+
dataset_splits: Dict[str, Dataset] = {}
|
58 |
+
for dataset_name, dataset_info in dataset.items():
|
59 |
+
if split in dataset_info.splits:
|
60 |
+
dataset_name = dataset_names_map.get(dataset_name, dataset_name)
|
61 |
+
dataset_splits[dataset_name] = dataset_info.splits[split]
|
62 |
+
return dataset_splits
|
63 |
+
|
64 |
+
|
65 |
+
split: str = st.selectbox("splits", ["raw", "processed"])
|
66 |
+
|
67 |
+
datasets: Dict[str, Dataset] = list_datasets()
|
68 |
+
# st.write(datasets)
|
69 |
+
|
70 |
+
filtered_datasets: Dict[str, Dataset] = filter_splits(datasets, split)
|
71 |
+
# st.write(filtered_datasets)
|
72 |
+
|
73 |
+
count_all_examples(filtered_datasets)
|
74 |
+
|
75 |
+
# Create a pie chart showing the number of examples per dataset
|
76 |
+
fig = px.pie(
|
77 |
+
values=[split.num_examples for split in filtered_datasets.values()],
|
78 |
+
names=list(filtered_datasets.keys()),
|
79 |
+
# title=f"Number of Examples per Dataset ({split} split)",
|
80 |
+
labels={"label": "Dataset", "value": "Number of Examples"},
|
81 |
+
)
|
82 |
+
|
83 |
+
# Update layout for better readability
|
84 |
+
fig.update_traces(textposition="inside", textinfo="value+label")
|
85 |
+
fig.update_layout(legend_title_text="Datasets", uniformtext_minsize=12, uniformtext_mode="hide")
|
86 |
+
|
87 |
+
chart = st.plotly_chart(fig, use_container_width=True)
|
88 |
+
|
89 |
+
|
90 |
+
dataset_name = st.selectbox("Select a dataset", list(filtered_datasets.keys()))
|
91 |
+
|
92 |
+
show_examples(dataset_name, split)
|