Spaces:
Runtime error
Runtime error
Download Backend/Dashboard.py from rabieifical/math-engine: direct link, hf CLI and curl.
- Browser
- Download file 827 Bytes
-
https://huggingface.co/spaces/rabieifical/math-engine/resolve/main/Backend/Dashboard.py
- Command line
-
hf download hf://spaces/rabieifical/math-engine/Backend/Dashboard.py
-
curl -L -o Dashboard.py https://huggingface.co/spaces/rabieifical/math-engine/resolve/main/Backend/Dashboard.py
827 Bytes
| import pandas as pd | |
| def get_dashboard_stats(state: dict) -> dict: | |
| if not state.get("ready"): | |
| return {} | |
| df = state["df"] | |
| index = state["index"] | |
| topic_distribution = [ | |
| {"name": str(k), "value": int(v)} | |
| for k, v in df["subject"].value_counts().to_dict().items() | |
| ] | |
| sorted_terms = sorted(index.items(), key=lambda x: len(x[1]), reverse=True) | |
| top_terms = [ | |
| { | |
| "term": term, | |
| "frequency": f"{sum(postings.values()):,}", | |
| "docs": list(postings.keys())[:5], | |
| } | |
| for term, postings in sorted_terms[:6] | |
| ] | |
| return { | |
| "total_docs": state["total_docs"], | |
| "vocab_size": len(index), | |
| "topic_distribution": topic_distribution, | |
| "top_terms": top_terms, | |
| } | |