Upload 3 files
Browse files- SPACES_README.md +1 -1
- app.py +14 -26
- requirements.txt +5 -6
SPACES_README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🔬
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
python_version: "3.10"
|
| 10 |
pinned: false
|
|
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.3.0
|
| 8 |
app_file: app.py
|
| 9 |
python_version: "3.10"
|
| 10 |
pinned: false
|
app.py
CHANGED
|
@@ -4,6 +4,10 @@ HuggingFace Spaces entry point for diffviews.
|
|
| 4 |
This file is the main entry point for HF Spaces deployment.
|
| 5 |
It downloads required data and checkpoints on startup, then launches the Gradio app.
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
Environment variables:
|
| 8 |
DIFFVIEWS_DATA_DIR: Override data directory (default: data)
|
| 9 |
DIFFVIEWS_CHECKPOINT: Which checkpoint to download (dmd2, edm, all, none; default: dmd2)
|
|
@@ -13,30 +17,6 @@ Environment variables:
|
|
| 13 |
import os
|
| 14 |
from pathlib import Path
|
| 15 |
|
| 16 |
-
# Monkey-patch gradio_client to handle additionalProperties: true
|
| 17 |
-
# This fixes a bug where dict-typed State components cause schema errors
|
| 18 |
-
# The bug is in _json_schema_to_python_type which recursively calls itself
|
| 19 |
-
# with schema['additionalProperties'] which can be True (boolean)
|
| 20 |
-
def _patch_gradio_client():
|
| 21 |
-
try:
|
| 22 |
-
import gradio_client.utils as client_utils
|
| 23 |
-
|
| 24 |
-
# Get the original function
|
| 25 |
-
original_func = client_utils._json_schema_to_python_type
|
| 26 |
-
|
| 27 |
-
def patched_json_schema_to_python_type(schema, defs=None):
|
| 28 |
-
# Handle case where schema is a boolean (additionalProperties: true)
|
| 29 |
-
if isinstance(schema, bool):
|
| 30 |
-
return "Any"
|
| 31 |
-
return original_func(schema, defs)
|
| 32 |
-
|
| 33 |
-
client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
|
| 34 |
-
print("[Patch] Applied gradio_client _json_schema_to_python_type fix")
|
| 35 |
-
except Exception as e:
|
| 36 |
-
print(f"[Patch] Could not patch gradio_client: {e}")
|
| 37 |
-
|
| 38 |
-
_patch_gradio_client()
|
| 39 |
-
|
| 40 |
# Data source configuration
|
| 41 |
DATA_REPO_ID = "mckell/diffviews_demo_data"
|
| 42 |
CHECKPOINT_URLS = {
|
|
@@ -179,7 +159,13 @@ def main():
|
|
| 179 |
ensure_data_ready(data_dir, checkpoints)
|
| 180 |
|
| 181 |
# Import and launch visualizer
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
print("\nInitializing visualizer...")
|
| 185 |
visualizer = GradioVisualizer(
|
|
@@ -196,7 +182,9 @@ def main():
|
|
| 196 |
server_name="0.0.0.0",
|
| 197 |
server_port=7860,
|
| 198 |
share=False, # Spaces handles public URL
|
| 199 |
-
|
|
|
|
|
|
|
| 200 |
)
|
| 201 |
|
| 202 |
|
|
|
|
| 4 |
This file is the main entry point for HF Spaces deployment.
|
| 5 |
It downloads required data and checkpoints on startup, then launches the Gradio app.
|
| 6 |
|
| 7 |
+
Requirements:
|
| 8 |
+
Python 3.10+
|
| 9 |
+
Gradio 6.0+
|
| 10 |
+
|
| 11 |
Environment variables:
|
| 12 |
DIFFVIEWS_DATA_DIR: Override data directory (default: data)
|
| 13 |
DIFFVIEWS_CHECKPOINT: Which checkpoint to download (dmd2, edm, all, none; default: dmd2)
|
|
|
|
| 17 |
import os
|
| 18 |
from pathlib import Path
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Data source configuration
|
| 21 |
DATA_REPO_ID = "mckell/diffviews_demo_data"
|
| 22 |
CHECKPOINT_URLS = {
|
|
|
|
| 159 |
ensure_data_ready(data_dir, checkpoints)
|
| 160 |
|
| 161 |
# Import and launch visualizer
|
| 162 |
+
import gradio as gr
|
| 163 |
+
from diffviews.visualization.app import (
|
| 164 |
+
GradioVisualizer,
|
| 165 |
+
create_gradio_app,
|
| 166 |
+
CUSTOM_CSS,
|
| 167 |
+
PLOTLY_HANDLER_JS,
|
| 168 |
+
)
|
| 169 |
|
| 170 |
print("\nInitializing visualizer...")
|
| 171 |
visualizer = GradioVisualizer(
|
|
|
|
| 182 |
server_name="0.0.0.0",
|
| 183 |
server_port=7860,
|
| 184 |
share=False, # Spaces handles public URL
|
| 185 |
+
theme=gr.themes.Soft(),
|
| 186 |
+
css=CUSTOM_CSS,
|
| 187 |
+
js=PLOTLY_HANDLER_JS,
|
| 188 |
)
|
| 189 |
|
| 190 |
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# DiffViews - HuggingFace Spaces Requirements
|
| 2 |
-
#
|
| 3 |
git+https://github.com/mckellcarter/diffviews.git
|
| 4 |
|
| 5 |
# Core dependencies
|
|
@@ -14,14 +14,13 @@ tqdm>=4.60.0
|
|
| 14 |
# Numba pinned for UMAP pickle compatibility
|
| 15 |
numba==0.58.1
|
| 16 |
|
| 17 |
-
# Visualization
|
| 18 |
-
gradio
|
| 19 |
-
gradio_client==0.15.0
|
| 20 |
plotly>=5.18.0
|
| 21 |
matplotlib>=3.5.0
|
| 22 |
|
| 23 |
-
# HuggingFace Hub
|
| 24 |
-
huggingface_hub>=0.
|
| 25 |
|
| 26 |
# Optional but useful
|
| 27 |
scipy>=1.7.0
|
|
|
|
| 1 |
# DiffViews - HuggingFace Spaces Requirements
|
| 2 |
+
# Requires Python 3.10+
|
| 3 |
git+https://github.com/mckellcarter/diffviews.git
|
| 4 |
|
| 5 |
# Core dependencies
|
|
|
|
| 14 |
# Numba pinned for UMAP pickle compatibility
|
| 15 |
numba==0.58.1
|
| 16 |
|
| 17 |
+
# Visualization - Gradio 6 for HF Spaces compatibility
|
| 18 |
+
gradio>=6.0.0
|
|
|
|
| 19 |
plotly>=5.18.0
|
| 20 |
matplotlib>=3.5.0
|
| 21 |
|
| 22 |
+
# HuggingFace Hub
|
| 23 |
+
huggingface_hub>=0.25.0
|
| 24 |
|
| 25 |
# Optional but useful
|
| 26 |
scipy>=1.7.0
|