airzy1 commited on
Commit
4141cd9
·
verified ·
1 Parent(s): 976adf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -40,20 +40,30 @@ processor = None
40
  model = None
41
 
42
 
43
- def load_model() -> None:
44
- global processor, model
45
- if model is not None and processor is not None:
 
 
 
46
  return
47
 
48
- print("Loading processor...", processor)
49
  processor = AutoProcessor.from_pretrained(
50
  MODEL_ID,
51
  token=HF_TOKEN if HF_TOKEN else None,
52
  min_pixels=MIN_PIXELS,
53
  max_pixels=MAX_PIXELS,
54
  )
 
 
55
 
56
- print("Loading model...", model)
 
 
 
 
 
57
  model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
58
  MODEL_ID,
59
  token=HF_TOKEN if HF_TOKEN else None,
@@ -61,12 +71,10 @@ def load_model() -> None:
61
  torch_dtype="auto",
62
  low_cpu_mem_usage=True,
63
  )
64
-
65
- print("model .eval()...")
66
  model.eval()
67
  print("Model ready")
68
 
69
- load_model();
70
 
71
  def prepare_image(image: Image.Image) -> Image.Image:
72
  """Upscale and sharpen to help with tiny text on pantry labels."""
@@ -114,7 +122,7 @@ def extract_json(text: str) -> Dict[str, Any]:
114
  PROMPT = """Analyze this pantry image in detail, list every ingredient"""
115
 
116
 
117
- @spaces.GPU(size="large", duration=240)
118
  def analyze_pantry(image: Image.Image):
119
  if image is None:
120
  return {"error": "Upload an image first."}
 
40
  model = None
41
 
42
 
43
+ processor = None
44
+ model = None
45
+
46
+ def load_processor() -> None:
47
+ global processor
48
+ if processor is not None:
49
  return
50
 
51
+ print("Loading processor...")
52
  processor = AutoProcessor.from_pretrained(
53
  MODEL_ID,
54
  token=HF_TOKEN if HF_TOKEN else None,
55
  min_pixels=MIN_PIXELS,
56
  max_pixels=MAX_PIXELS,
57
  )
58
+ print("Processor ready")
59
+
60
 
61
+ def load_model() -> None:
62
+ global model
63
+ if model is not None:
64
+ return
65
+
66
+ print("Loading model...")
67
  model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
68
  MODEL_ID,
69
  token=HF_TOKEN if HF_TOKEN else None,
 
71
  torch_dtype="auto",
72
  low_cpu_mem_usage=True,
73
  )
 
 
74
  model.eval()
75
  print("Model ready")
76
 
77
+ load_processor()
78
 
79
  def prepare_image(image: Image.Image) -> Image.Image:
80
  """Upscale and sharpen to help with tiny text on pantry labels."""
 
122
  PROMPT = """Analyze this pantry image in detail, list every ingredient"""
123
 
124
 
125
+ @spaces.GPU(size="large", duration=120)
126
  def analyze_pantry(image: Image.Image):
127
  if image is None:
128
  return {"error": "Upload an image first."}