richiam commited on
Commit
b31bdfc
·
verified ·
1 Parent(s): c140eef

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +28 -11
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1755,25 +1755,44 @@ def _uniprot_card(pmid):
1755
  ], className="mb-3")
1756
 
1757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1758
  def _load_cluster_csv(model, min_val, threshold):
1759
  """Return the ALL_FIELDS dataframe or None. Supports .csv.gz and .csv."""
1760
  base = os.path.join(GRID_BASE, f"model={model}", f"min={min_val}",
1761
  f"t={threshold}_ALL_FIELDS")
1762
- print(f"[debug] _load_cluster_csv: GRID_BASE={GRID_BASE}, model={model}, min={min_val}, t={threshold}", flush=True)
1763
  for ext in (".csv.gz", ".csv"):
1764
  path = base + ext
1765
- exists = os.path.isfile(path)
1766
- print(f"[debug] trying {path} -> exists={exists}", flush=True)
1767
- if not exists:
1768
  continue
 
 
1769
  try:
1770
  return pd.read_csv(path, compression="gzip" if ext == ".csv.gz" else None)
1771
- except Exception as e:
1772
- print(f"[debug] read error ({e}), trying plain csv")
1773
  try:
1774
- return pd.read_csv(path)
1775
- except Exception as e2:
1776
- print(f"[debug] plain csv also failed: {e2}")
1777
  continue
1778
  return None
1779
 
@@ -1962,11 +1981,9 @@ def _distribution_figure(cdf, field_name, top_n=20):
1962
  Input("cluster-group-filter", "value"),
1963
  )
1964
  def update_cluster_plot(model, min_val, threshold, field, plot_type, top_n, groups):
1965
- print(f"[debug] update_cluster_plot called: model={model}, min={min_val}, t={threshold}, field={field}, plot_type={plot_type}", flush=True)
1966
  empty_fig = go.Figure()
1967
  empty_fig.update_layout(paper_bgcolor="#ffffff", plot_bgcolor="#f9fafc")
1968
  if not all([model, min_val, threshold, field, plot_type]):
1969
- print(f"[debug] early return: missing values", flush=True)
1970
  return empty_fig, "Select all parameters above."
1971
 
1972
  cdf = _load_cluster_csv(model, min_val, threshold)
 
1755
  ], className="mb-3")
1756
 
1757
 
1758
+ _HF_REPO = "richiam/ProtoPure"
1759
+ _HF_APP_ROOT = "/app"
1760
+
1761
+
1762
+ def _resolve_xet_file(local_path):
1763
+ """If local_path is an HF Xet pointer, download actual content and overwrite it."""
1764
+ try:
1765
+ with open(local_path, "rb") as f:
1766
+ magic = f.read(2)
1767
+ if magic == b"\x1f\x8b":
1768
+ return # already proper gzip
1769
+ rel = os.path.relpath(local_path, _HF_APP_ROOT)
1770
+ print(f"[xet] Downloading {rel} from HF Hub...", flush=True)
1771
+ from huggingface_hub import hf_hub_download
1772
+ import shutil
1773
+ actual = hf_hub_download(repo_id=_HF_REPO, filename=rel, repo_type="space")
1774
+ shutil.copy2(actual, local_path)
1775
+ print(f"[xet] Cached {rel}", flush=True)
1776
+ except Exception as e:
1777
+ print(f"[xet] Failed to resolve {local_path}: {e}", flush=True)
1778
+
1779
+
1780
  def _load_cluster_csv(model, min_val, threshold):
1781
  """Return the ALL_FIELDS dataframe or None. Supports .csv.gz and .csv."""
1782
  base = os.path.join(GRID_BASE, f"model={model}", f"min={min_val}",
1783
  f"t={threshold}_ALL_FIELDS")
 
1784
  for ext in (".csv.gz", ".csv"):
1785
  path = base + ext
1786
+ if not os.path.isfile(path):
 
 
1787
  continue
1788
+ if ext == ".csv.gz":
1789
+ _resolve_xet_file(path)
1790
  try:
1791
  return pd.read_csv(path, compression="gzip" if ext == ".csv.gz" else None)
1792
+ except Exception:
 
1793
  try:
1794
+ return pd.read_csv(path, compression=None)
1795
+ except Exception:
 
1796
  continue
1797
  return None
1798
 
 
1981
  Input("cluster-group-filter", "value"),
1982
  )
1983
  def update_cluster_plot(model, min_val, threshold, field, plot_type, top_n, groups):
 
1984
  empty_fig = go.Figure()
1985
  empty_fig.update_layout(paper_bgcolor="#ffffff", plot_bgcolor="#f9fafc")
1986
  if not all([model, min_val, threshold, field, plot_type]):
 
1987
  return empty_fig, "Select all parameters above."
1988
 
1989
  cdf = _load_cluster_csv(model, min_val, threshold)
requirements.txt CHANGED
@@ -3,3 +3,4 @@ plotly==6.6.0
3
  dash-bootstrap-components==2.0.4
4
  pandas==3.0.2
5
  flask==3.1.3
 
 
3
  dash-bootstrap-components==2.0.4
4
  pandas==3.0.2
5
  flask==3.1.3
6
+ huggingface_hub>=0.23.0