Skip to content

Commit d95f421

Browse files
committed
A backend service which receives excel, csv files and displays its content
1 parent d7b7184 commit d95f421

6 files changed

Lines changed: 293 additions & 7 deletions

File tree

README.md

Lines changed: 209 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,214 @@
1-
# dsqusss
1+
# 🧩 Dataset Quality Scoring Engine — System Framework (Markdown)
22

3-
Python package scaffold for the `dsqus` repository.
3+
#️⃣ 1. Overview
44

5-
## Publish on every push
5+
The Dataset Quality Scoring Engine (DQS) evaluates the quality of any dataset using automated, model-agnostic metrics.
6+
The system processes user-uploaded datasets, computes embeddings, analyzes statistical and semantic properties, and outputs a standardized quality score (0–100) along with detailed submetrics.
67

7-
This repository includes a GitHub Actions workflow that builds and publishes the package on every push.
8+
## 2. High-Level Workflow
89

9-
Set this repository secret before pushing:
10+
User Upload → Preprocessing → Embedding → Metric Computation → Scoring → Report Generation → Cleanup
1011

11-
- `PYPI_API_TOKEN`: your PyPI token (`pypi-...`).
12+
## 3. Input Specifications
13+
14+
The system accepts:
15+
16+
jsonl
17+
json
18+
txt
19+
csv
20+
folder of text/code files
21+
PDFs (extracted into text)
22+
23+
## 4. Preprocessing Pipeline
24+
25+
Validate file format
26+
Convert to normalized internal format (list[str or dict])
27+
Clean text:
28+
remove control chars
29+
normalize whitespace
30+
optional: strip HTML/markup
31+
Segment long documents into meaningful chunks
32+
Remove empty or invalid samples
33+
34+
Output: clean, structured dataset
35+
36+
## 5. Embedding Generation
37+
38+
Two embedding flows:
39+
40+
5.1 Local Embeddings (Per Upload)
41+
42+
Used for:
43+
44+
redundancy
45+
coherence
46+
diversity
47+
factual contradictions
48+
clustering/domain analysis
49+
50+
These embeddings exist only for the request and are deleted afterward.
51+
52+
5.2 Global Reference Embeddings (Static)
53+
54+
Used only for novelty detection.
55+
56+
Pre-built FAISS/Vector DB containing ~1M representative samples:
57+
58+
Wikipedia
59+
Common Crawl samples
60+
C4 slices
61+
StackOverflow
62+
Books corpus
63+
Public domain corpora
64+
65+
This is static, never modified by user uploads.
66+
67+
## 6. Metric Computation
68+
69+
DQS computes 10 core quality metrics:
70+
71+
6.1 Redundancy Score
72+
compute embedding similarity within dataset
73+
clustering density = redundancy
74+
score = inverse redundancy
75+
6.2 Malware / Toxicity Score
76+
run samples through pre-trained toxicity classifier
77+
aggregate severity
78+
6.3 Diversity Score
79+
linguistic diversity (entropy, vocab richness)
80+
semantic diversity (embedding variance)
81+
6.4 Readability Score
82+
Flesch–Kincaid
83+
sentence complexity
84+
coherency heuristics
85+
6.5 Semantic Coherence
86+
embedding flow consistency
87+
perplexity using a small reference LLM
88+
6.6 Novelty Score
89+
compare against global reference corpus
90+
nearest neighbor distance = novelty measure
91+
6.7 Structure Quality
92+
93+
Applicable to:
94+
95+
JSON
96+
code
97+
SQL
98+
XML
99+
YAML
100+
101+
Checks:
102+
103+
syntax validity
104+
AST parsing success
105+
6.8 Factual Conflict Score
106+
sample random pairs
107+
pass to NLI contradiction model
108+
aggregate contradictions
109+
6.9 Domain Balance Score
110+
cluster dataset embeddings
111+
measure cluster distribution via entropy
112+
6.10 Length Distribution Score
113+
detect outliers
114+
analyze token distribution
115+
116+
## 7. Composite Score Calculation
117+
118+
All metrics normalized 0–100.
119+
120+
Weighted aggregation formula:
121+
122+
overall_score =
123+
0.15*redundancy +
124+
0.10*toxicity +
125+
0.10*diversity +
126+
0.10*readability +
127+
0.10*coherence +
128+
0.10*novelty +
129+
0.10*structure +
130+
0.10*factual_conflict +
131+
0.075*domain_balance +
132+
0.075*length_distribution
133+
134+
## 8. Report Generation
135+
136+
Output includes:
137+
138+
8.1 JSON Report
139+
140+
Contains:
141+
142+
overall_score
143+
all sub-scores
144+
dataset metadata
145+
top detected issues
146+
summary of duplicates
147+
domain distribution histogram
148+
8.2 Human-Readable Text Report
149+
simple explanations
150+
listed issues
151+
recommendations
152+
optional PDF
153+
154+
## 9. System Architecture
155+
156+
Components
157+
API Layer
158+
file upload
159+
async processing
160+
report delivery
161+
Compute Engine
162+
embeddings
163+
scoring logic
164+
batching
165+
concurrency optimized
166+
Reference Store
167+
FAISS/Qdrant global novelty index
168+
static
169+
Models Folder
170+
toxicity classifier
171+
contradiction/NLI model
172+
small LLM for perplexity
173+
174+
## 10. Execution Flow Diagram
175+
176+
[Upload]
177+
178+
[Preprocess]
179+
180+
[Generate Local Embeddings]
181+
182+
[Compute All Self-Contained Metrics]
183+
184+
[Compare with Global Reference Embeddings]
185+
186+
[Aggregate Scores]
187+
188+
[Generate JSON + Text Report]
189+
190+
[Return to User]
191+
192+
[Delete all temp embeddings + data]
193+
194+
## 11. Privacy Model
195+
196+
No dataset stored after processing
197+
No embeddings stored
198+
Only the report is saved (optional)
199+
Global reference embeddings NEVER contain user data
200+
Fully GDPR-safe
201+
202+
## 12. MVP Boundary (Important)
203+
204+
Not included in v1:
205+
206+
dataset cleaning
207+
dataset repair
208+
dataset marketplace
209+
collaborative annotation
210+
data augmentation
211+
agentic workflows
212+
213+
You stay laser-focused on:
214+
analysis → scoring → reporting.

dsqus/engine/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Engine package for the dsqus backend service."""
2+
3+
from .app import app
4+
5+
__all__ = ["app"]

dsqus/engine/app.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import annotations
2+
3+
from fastapi import FastAPI, File, HTTPException, UploadFile
4+
from fastapi.middleware.cors import CORSMiddleware
5+
6+
try:
7+
from .file_parser import parse_uploaded_file
8+
except ImportError: # Allows `uvicorn app:app` from the engine directory.
9+
from file_parser import parse_uploaded_file
10+
11+
app = FastAPI(title="dsqus file upload API")
12+
13+
app.add_middleware(
14+
CORSMiddleware,
15+
allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"],
16+
allow_credentials=True,
17+
allow_methods=["*"],
18+
allow_headers=["*"],
19+
)
20+
21+
22+
@app.get("/health")
23+
def health_check() -> dict[str, str]:
24+
return {"status": "ok"}
25+
26+
27+
@app.post("/upload")
28+
async def upload_file(file: UploadFile = File(...)) -> dict[str, object]:
29+
if not file.filename:
30+
raise HTTPException(status_code=400, detail="A filename is required.")
31+
32+
try:
33+
content = await file.read()
34+
return parse_uploaded_file(file.filename, content)
35+
except ValueError as exc:
36+
raise HTTPException(status_code=400, detail=str(exc)) from exc
37+
except Exception as exc: # pragma: no cover - defensive guard for corrupted files
38+
raise HTTPException(status_code=400, detail=f"Unable to read file: {exc}") from exc

dsqus/engine/file_parser.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import annotations
2+
3+
from io import BytesIO
4+
from pathlib import Path
5+
6+
import pandas as pd
7+
8+
9+
SUPPORTED_EXTENSIONS = {".csv", ".xls", ".xlsx"}
10+
11+
12+
def parse_uploaded_file(filename: str, content: bytes) -> dict[str, object]:
13+
extension = Path(filename).suffix.lower()
14+
if extension not in SUPPORTED_EXTENSIONS:
15+
raise ValueError("Only CSV and Excel files are supported.")
16+
17+
if extension == ".csv":
18+
frame = pd.read_csv(BytesIO(content))
19+
else:
20+
frame = pd.read_excel(BytesIO(content))
21+
22+
frame = frame.fillna("")
23+
columns = list(frame.columns.astype(str))
24+
rows = frame.to_dict(orient="records")
25+
26+
return {
27+
"filename": filename,
28+
"columns": columns,
29+
"rows": rows,
30+
"rowCount": len(rows),
31+
}

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ requires-python = ">=3.10"
1111
authors = [
1212
{ name = "Sanjog Sigdel" }
1313
]
14-
dependencies = []
14+
dependencies = [
15+
"fastapi>=0.115",
16+
"uvicorn[standard]>=0.30",
17+
"python-multipart>=0.0.9",
18+
"pandas>=2.2",
19+
"openpyxl>=3.1",
20+
]
1521

1622
[project.urls]
1723
Homepage = "https://github.com/sigdelsanjog/dsqus"

ui/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
.vite/

0 commit comments

Comments
 (0)