edeler commited on
Commit
5cbc475
·
1 Parent(s): 12c0045

Add support for custom RF-DETR model upload via direct upload or HF Hub repository

Browse files
Files changed (2) hide show
  1. README.md +18 -5
  2. app.py +18 -1
README.md CHANGED
@@ -51,15 +51,28 @@ This application is designed to run on Hugging Face Spaces. The following files
51
 
52
  ## Model Loading
53
 
54
- **RF-DETR Model:**
55
- - Upload your trained `rf-detr-medium.pth` file to the Space
56
- - The application will automatically find and load it
57
-
58
- **MedGemma Models:**
59
  - Models download automatically from Hugging Face Hub on first use
60
  - No manual installation required
61
  - Choose between 4B (faster) or 27B (more accurate) models
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  ## Space Configuration
64
 
65
  For optimal performance, configure your Space settings:
 
51
 
52
  ## Model Loading
53
 
54
+ **MedGemma Models (Automatic):**
 
 
 
 
55
  - Models download automatically from Hugging Face Hub on first use
56
  - No manual installation required
57
  - Choose between 4B (faster) or 27B (more accurate) models
58
 
59
+ **RF-DETR Model (Your Custom Model):**
60
+ You have two options for uploading your custom RF-DETR model:
61
+
62
+ ### Option 1: Direct Upload (Simple)
63
+ 1. Upload your `rf-detr-medium.pth` file directly to your Space
64
+ 2. The app will automatically find and use it
65
+
66
+ ### Option 2: Model Repository (Recommended)
67
+ 1. Create a separate Hugging Face model repository (e.g., `your-username/rf-detr-medical`)
68
+ 2. Upload your model files there
69
+ 3. Set the environment variable `RFDETR_HF_REPO` to your repository ID
70
+
71
+ **To set the environment variable:**
72
+ - Go to your Space settings
73
+ - Add `RFDETR_HF_REPO` with your model repository ID (e.g., `your-username/rf-detr-medical`)
74
+ - The app will download from your repository automatically
75
+
76
  ## Space Configuration
77
 
78
  For optimal performance, configure your Space settings:
app.py CHANGED
@@ -90,8 +90,25 @@ memory_manager = MemoryManager()
90
 
91
  def find_checkpoint() -> Optional[str]:
92
  """Find RF-DETR checkpoint in various locations."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  candidates = [
94
- "rf-detr-medium.pth", # Current directory
95
  "/tmp/results/checkpoint_best_total.pth",
96
  "/tmp/results/checkpoint_best_ema.pth",
97
  "/tmp/results/checkpoint_best_regular.pth",
 
90
 
91
  def find_checkpoint() -> Optional[str]:
92
  """Find RF-DETR checkpoint in various locations."""
93
+ # Check for HuggingFace model repository first (recommended)
94
+ import os
95
+ hf_model_id = os.environ.get("RFDETR_HF_REPO")
96
+ if hf_model_id:
97
+ try:
98
+ from huggingface_hub import hf_hub_download
99
+ print(f"Downloading RF-DETR from HuggingFace Hub: {hf_model_id}")
100
+ checkpoint_path = hf_hub_download(
101
+ repo_id=hf_model_id,
102
+ filename="rf-detr-medium.pth",
103
+ cache_dir="/tmp/hf_cache"
104
+ )
105
+ return checkpoint_path
106
+ except Exception as e:
107
+ print(f"Failed to download from HF Hub: {e}")
108
+
109
+ # Fallback to local files
110
  candidates = [
111
+ "rf-detr-medium.pth", # Current directory (direct upload)
112
  "/tmp/results/checkpoint_best_total.pth",
113
  "/tmp/results/checkpoint_best_ema.pth",
114
  "/tmp/results/checkpoint_best_regular.pth",