from __future__ import annotations import os from pathlib import Path from typing import List import pandas as pd import streamlit as st import plotly.express as px from pyvis.network import Network import streamlit.components.v1 as components HF_REPO_ID = os.environ.get("HF_REPO_ID", "") HF_TOKEN = os.environ.get("HF_TOKEN", "") st.set_page_config(page_title="CitationHub", page_icon="π", layout="wide") ALLOWED_INTENTS = [ "background","uses","similarities","motivation", "differences","future_work","extends", ] INTENT_COLORS = { "background":"#94a3b8","uses":"#22c55e","similarities":"#3b82f6", "motivation":"#f59e0b","differences":"#ef4444", "future_work":"#8b5cf6","extends":"#06b6d4", } NODE_COLORS = { "seed_paper":"#111827","citing_paper":"#dbeafe","citation_event":"#fde68a", "journal":"#ede9fe","author":"#fee2e2","affiliation":"#fae8ff", "city":"#cffafe","country":"#ffedd5","field":"#e0e7ff","intent":"#dcfce7", } NODE_TYPE_COLORS = { "seed_paper":"#111827","citing_paper":"#3b82f6","citation_event":"#f59e0b", "journal":"#8b5cf6","author":"#ef4444","affiliation":"#ec4899", "city":"#06b6d4","country":"#f97316","field":"#6366f1","intent":"#22c55e", } DEFAULT_DATA_DIR = Path(os.environ.get( "CITATIONHUB_DATA_DIR", r"C:\Users\user\OneDrive\λ°ν νλ©΄\Citehub_huggingface\data", )) def fmt_num(x): try: return f"{int(x):,}" except: return "-" def _hf_download(filename: str) -> str: from huggingface_hub import hf_hub_download return hf_hub_download( repo_id=HF_REPO_ID, repo_type="dataset", filename=f"data/{filename}", token=HF_TOKEN or None, ) def _read(filename: str, data_dir: Path | None = None) -> pd.DataFrame: if HF_REPO_ID: return pd.read_parquet(_hf_download(filename)) return pd.read_parquet(data_dir / filename) def inject_fullscreen(html: str) -> str: btn = """