Spaces:
Running
on
Zero
Running
on
Zero
Joseph Pollack
commited on
attempts model loading fix
Browse files
app.py
CHANGED
|
@@ -37,44 +37,19 @@ class LOperatorDemo:
|
|
| 37 |
if not HF_TOKEN:
|
| 38 |
return "❌ HF_TOKEN not found. Please set HF_TOKEN in Spaces secrets."
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
token=HF_TOKEN
|
| 54 |
-
)
|
| 55 |
-
|
| 56 |
-
except Exception as e:
|
| 57 |
-
logger.warning(f"Standard loading failed: {str(e)}")
|
| 58 |
-
logger.info("Attempting fallback loading approach...")
|
| 59 |
-
|
| 60 |
-
# Fallback: try loading with explicit model type
|
| 61 |
-
self.processor = AutoProcessor.from_pretrained(
|
| 62 |
-
MODEL_ID,
|
| 63 |
-
trust_remote_code=True,
|
| 64 |
-
token=HF_TOKEN,
|
| 65 |
-
revision="main"
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 69 |
-
MODEL_ID,
|
| 70 |
-
torch_dtype=torch.bfloat16 if DEVICE == "cuda" else torch.float32,
|
| 71 |
-
trust_remote_code=True,
|
| 72 |
-
device_map="auto" if DEVICE == "cuda" else None,
|
| 73 |
-
token=HF_TOKEN,
|
| 74 |
-
revision="main",
|
| 75 |
-
ignore_mismatched_sizes=True
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
if DEVICE == "cpu":
|
| 79 |
self.model = self.model.to(DEVICE)
|
| 80 |
|
|
@@ -207,18 +182,18 @@ print("✅ Model loading completed!")
|
|
| 207 |
|
| 208 |
# Load example episodes
|
| 209 |
def load_example_episodes():
|
| 210 |
-
"""Load example episodes from the extracted data"""
|
| 211 |
examples = []
|
| 212 |
-
|
| 213 |
try:
|
| 214 |
# Load episode 13
|
| 215 |
with open("extracted_episodes_duckdb/episode_13/metadata.json", "r") as f:
|
| 216 |
episode_13 = json.load(f)
|
| 217 |
-
|
| 218 |
-
# Load episode 53
|
| 219 |
with open("extracted_episodes_duckdb/episode_53/metadata.json", "r") as f:
|
| 220 |
episode_53 = json.load(f)
|
| 221 |
-
|
| 222 |
# Load episode 73
|
| 223 |
with open("extracted_episodes_duckdb/episode_73/metadata.json", "r") as f:
|
| 224 |
episode_73 = json.load(f)
|
|
@@ -227,22 +202,35 @@ def load_example_episodes():
|
|
| 227 |
examples = [
|
| 228 |
[
|
| 229 |
"extracted_episodes_duckdb/episode_13/screenshots/screenshot_1.png",
|
| 230 |
-
"Episode 13: Navigate app interface"
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
"extracted_episodes_duckdb/episode_53/screenshots/screenshot_1.png",
|
| 234 |
-
"Episode 53: App interaction example"
|
| 235 |
-
|
| 236 |
-
|
| 237 |
"extracted_episodes_duckdb/episode_73/screenshots/screenshot_1.png",
|
| 238 |
-
"Episode 73: Device control task"
|
| 239 |
-
|
| 240 |
]
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
except Exception as e:
|
| 243 |
logger.error(f"Error loading examples: {str(e)}")
|
| 244 |
examples = []
|
| 245 |
-
|
|
|
|
| 246 |
return examples
|
| 247 |
|
| 248 |
# Create Gradio interface
|
|
|
|
| 37 |
if not HF_TOKEN:
|
| 38 |
return "❌ HF_TOKEN not found. Please set HF_TOKEN in Spaces secrets."
|
| 39 |
|
| 40 |
+
# Load model following the working example pattern
|
| 41 |
+
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 42 |
+
MODEL_ID,
|
| 43 |
+
device_map="auto",
|
| 44 |
+
torch_dtype=torch.bfloat16 if DEVICE == "cuda" else torch.float32,
|
| 45 |
+
trust_remote_code=True
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Load processor
|
| 49 |
+
self.processor = AutoProcessor.from_pretrained(
|
| 50 |
+
MODEL_ID,
|
| 51 |
+
trust_remote_code=True
|
| 52 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
if DEVICE == "cpu":
|
| 54 |
self.model = self.model.to(DEVICE)
|
| 55 |
|
|
|
|
| 182 |
|
| 183 |
# Load example episodes
|
| 184 |
def load_example_episodes():
|
| 185 |
+
"""Load example episodes from the extracted data with error handling"""
|
| 186 |
examples = []
|
| 187 |
+
|
| 188 |
try:
|
| 189 |
# Load episode 13
|
| 190 |
with open("extracted_episodes_duckdb/episode_13/metadata.json", "r") as f:
|
| 191 |
episode_13 = json.load(f)
|
| 192 |
+
|
| 193 |
+
# Load episode 53
|
| 194 |
with open("extracted_episodes_duckdb/episode_53/metadata.json", "r") as f:
|
| 195 |
episode_53 = json.load(f)
|
| 196 |
+
|
| 197 |
# Load episode 73
|
| 198 |
with open("extracted_episodes_duckdb/episode_73/metadata.json", "r") as f:
|
| 199 |
episode_73 = json.load(f)
|
|
|
|
| 202 |
examples = [
|
| 203 |
[
|
| 204 |
"extracted_episodes_duckdb/episode_13/screenshots/screenshot_1.png",
|
| 205 |
+
f"Episode 13: {episode_13.get('goal', 'Navigate app interface')[:50]}..."
|
| 206 |
+
),
|
| 207 |
+
(
|
| 208 |
+
"extracted_episodes_duckdb/episode_53/screenshots/screenshot_1.png",
|
| 209 |
+
f"Episode 53: {episode_53.get('goal', 'App interaction example')[:50]}..."
|
| 210 |
+
),
|
| 211 |
+
(
|
| 212 |
"extracted_episodes_duckdb/episode_73/screenshots/screenshot_1.png",
|
| 213 |
+
f"Episode 73: {episode_73.get('goal', 'Device control task')[:50]}..."
|
| 214 |
+
)
|
| 215 |
]
|
| 216 |
+
|
| 217 |
+
# Validate each example by checking if image file exists and is readable
|
| 218 |
+
for image_path, description in examples:
|
| 219 |
+
try:
|
| 220 |
+
# Try to open the image to validate it
|
| 221 |
+
from PIL import Image
|
| 222 |
+
with Image.open(image_path) as img:
|
| 223 |
+
# If we get here, the image is valid
|
| 224 |
+
examples.append([image_path, description])
|
| 225 |
+
except Exception as img_error:
|
| 226 |
+
logger.warning(f"Skipping invalid image {image_path}: {str(img_error)}")
|
| 227 |
+
continue
|
| 228 |
+
|
| 229 |
except Exception as e:
|
| 230 |
logger.error(f"Error loading examples: {str(e)}")
|
| 231 |
examples = []
|
| 232 |
+
|
| 233 |
+
logger.info(f"Loaded {len(examples)} valid examples")
|
| 234 |
return examples
|
| 235 |
|
| 236 |
# Create Gradio interface
|