Spaces:
Runtime error
Runtime error
Update app/main.py
Browse files- app/main.py +55 -52
app/main.py
CHANGED
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
| 9 |
from fastapi import FastAPI, Query, HTTPException
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
|
| 12 |
-
from app.api import
|
| 13 |
from app.registry.catalog import DATASETS, ALGORITHMS
|
| 14 |
|
| 15 |
from app.services.hf_datasets import (
|
|
@@ -99,62 +99,65 @@ def list_beeline_datasets_route():
|
|
| 99 |
return [
|
| 100 |
d.id for d in datasets
|
| 101 |
if d.id.startswith("cskokgibbs/BEELINE")
|
|
|
|
| 102 |
]
|
| 103 |
|
| 104 |
-
# @app.get("/datasets", response_model=List[str])
|
| 105 |
-
# def list_datasets():
|
| 106 |
-
# hf_datasets = api.list_datasets(author=OWNER)
|
| 107 |
-
# return [
|
| 108 |
-
# d.id for d in hf_datasets
|
| 109 |
-
# if d.id.startswith(f"{OWNER}/BEELINE")
|
| 110 |
-
# ]
|
| 111 |
-
|
| 112 |
-
# @app.get("/dataset", response_model=DatasetMetadata)
|
| 113 |
-
# def get_dataset_metadata_route(
|
| 114 |
-
# dataset_id: str = Query(DEFAULT_DATASET_ID)
|
| 115 |
-
# ):
|
| 116 |
-
# cached = conn.execute(
|
| 117 |
-
# "SELECT * FROM datasets WHERE id = ?",
|
| 118 |
-
# (dataset_id,)
|
| 119 |
-
# ).fetchone()
|
| 120 |
-
|
| 121 |
-
# if cached:
|
| 122 |
-
# return dict(zip(
|
| 123 |
-
# ["id", "name", "organism", "type", "genes", "cells", "edges", "source", "last_updated"],
|
| 124 |
-
# cached
|
| 125 |
-
# ))
|
| 126 |
-
|
| 127 |
-
# try:
|
| 128 |
-
# ds = load_dataset(dataset_id)
|
| 129 |
-
# except Exception as e:
|
| 130 |
-
# raise HTTPException(status_code=404, detail=str(e))
|
| 131 |
-
|
| 132 |
-
# expr = ds["train"]
|
| 133 |
-
# genes = len(expr.column_names) - 1
|
| 134 |
-
# cells = expr.num_rows
|
| 135 |
-
# edges = ds["gold_standard"].num_rows if "gold_standard" in ds else None
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
|
| 157 |
-
|
| 158 |
|
| 159 |
|
| 160 |
# --------------
|
|
@@ -232,7 +235,7 @@ def list_beeline_datasets_route():
|
|
| 232 |
# return record
|
| 233 |
|
| 234 |
# Routers come AFTER middleware
|
| 235 |
-
app.include_router(datasets.router)
|
| 236 |
app.include_router(algorithms.router)
|
| 237 |
app.include_router(runs.router)
|
| 238 |
app.include_router(docs.router)
|
|
|
|
| 9 |
from fastapi import FastAPI, Query, HTTPException
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
|
| 12 |
+
from app.api import algorithms, runs, docs
|
| 13 |
from app.registry.catalog import DATASETS, ALGORITHMS
|
| 14 |
|
| 15 |
from app.services.hf_datasets import (
|
|
|
|
| 99 |
return [
|
| 100 |
d.id for d in datasets
|
| 101 |
if d.id.startswith("cskokgibbs/BEELINE")
|
| 102 |
+
and not d.id.endswith("-cache")
|
| 103 |
]
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
@app.get("/datasets", response_model=List[str])
|
| 107 |
+
def list_datasets():
|
| 108 |
+
hf_datasets = api.list_datasets(author=OWNER)
|
| 109 |
+
return [
|
| 110 |
+
d.id for d in hf_datasets
|
| 111 |
+
if d.id.startswith(f"{OWNER}/BEELINE")
|
| 112 |
+
and not d.id.endswith("-cache")
|
| 113 |
+
]
|
| 114 |
|
| 115 |
+
@app.get("/dataset", response_model=DatasetMetadata)
|
| 116 |
+
def get_dataset_metadata_route(
|
| 117 |
+
dataset_id: str = Query(DEFAULT_DATASET_ID)
|
| 118 |
+
):
|
| 119 |
+
cached = conn.execute(
|
| 120 |
+
"SELECT * FROM datasets WHERE id = ?",
|
| 121 |
+
(dataset_id,)
|
| 122 |
+
).fetchone()
|
| 123 |
+
|
| 124 |
+
if cached:
|
| 125 |
+
return dict(zip(
|
| 126 |
+
["id", "name", "organism", "type", "genes", "cells", "edges", "source", "last_updated"],
|
| 127 |
+
cached
|
| 128 |
+
))
|
| 129 |
+
|
| 130 |
+
try:
|
| 131 |
+
ds = load_dataset(dataset_id)
|
| 132 |
+
except Exception as e:
|
| 133 |
+
raise HTTPException(status_code=404, detail=str(e))
|
| 134 |
+
|
| 135 |
+
expr = ds["train"]
|
| 136 |
+
genes = len(expr.column_names) - 1
|
| 137 |
+
cells = expr.num_rows
|
| 138 |
+
edges = ds["gold_standard"].num_rows if "gold_standard" in ds else None
|
| 139 |
+
|
| 140 |
+
info = api.dataset_info(dataset_id)
|
| 141 |
+
card = info.cardData or {}
|
| 142 |
+
|
| 143 |
+
record = {
|
| 144 |
+
"id": dataset_id,
|
| 145 |
+
"name": dataset_id.split("/")[-1],
|
| 146 |
+
"organism": card.get("organism", "unknown"),
|
| 147 |
+
"type": card.get("dataset_type", "scRNA-seq"),
|
| 148 |
+
"genes": genes,
|
| 149 |
+
"cells": cells,
|
| 150 |
+
"edges": edges,
|
| 151 |
+
"source": "huggingface",
|
| 152 |
+
"last_updated": info.last_modified,
|
| 153 |
+
}
|
| 154 |
|
| 155 |
+
conn.execute(
|
| 156 |
+
"INSERT INTO datasets VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
| 157 |
+
tuple(record.values())
|
| 158 |
+
)
|
| 159 |
|
| 160 |
+
return record
|
| 161 |
|
| 162 |
|
| 163 |
# --------------
|
|
|
|
| 235 |
# return record
|
| 236 |
|
| 237 |
# Routers come AFTER middleware
|
| 238 |
+
# app.include_router(datasets.router)
|
| 239 |
app.include_router(algorithms.router)
|
| 240 |
app.include_router(runs.router)
|
| 241 |
app.include_router(docs.router)
|