File size: 1,361 Bytes
43bc104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf0041a
43bc104
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os

import dotenv
import pandas as pd
from datasets import load_dataset
from fasthtml.common import *

dotenv.load_dotenv()

app, rt = fast_app()
from huggingface_hub import login, whoami

login(token=os.environ.get("HF_TOKEN"))

hf_user = whoami(os.environ.get("HF_TOKEN"))["name"]
HF_REPO_ID = f"{hf_user}/zotero-answer-ai-articles"


@rt("/")
async def get():
    """Dataset viewer home page"""
    return Titled(
        "Zotero Dataset Viewer",
        Form(
            Input(id="dataset_subset", placeholder="Enter dataset subset"),
            Button("Load Dataset"),
            hx_post="/load_dataset",
            hx_target="#dataset_content",
        ),
        Div(id="dataset_content"),
    )


@rt("/load_dataset")
async def post(dataset_subset: str):
    """Load and display dataset"""
    try:
        dataset = load_dataset(HF_REPO_ID, dataset_subset, split="train")
        df = pd.DataFrame(dataset[:10])  # Load first 10 rows
        table = df.to_html(classes="table", index=False)

        return Div(
            H2(f"Dataset: {HF_REPO_ID}, Subset: {dataset_subset}"),
            P(f"Number of rows: {len(dataset)}"),
            P(f"Columns: {', '.join(df.columns)}"),
            Div(NotStr(table), cls="table-responsive"),
        )

    except Exception as e:
        return Div(f"Error loading dataset: {str(e)}")


serve()