Shakir60 commited on
Commit
3c13553
·
verified ·
1 Parent(s): 59d2300

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -148,20 +148,9 @@ class ImageAnalyzer:
148
  logger.error(f"Model initialization error: {e}")
149
  return None
150
 
151
- @st.cache_data # Cache preprocessed images
152
  def preprocess_image(self, image_bytes):
153
  """Preprocess image for model input"""
154
- try:
155
- image = Image.open(image_bytes)
156
- if image.mode != 'RGB':
157
- image = image.convert('RGB')
158
-
159
- width, height = 224, 224
160
- image = image.resize((width, height), Image.Resampling.LANCZOS)
161
- return image
162
- except Exception as e:
163
- logger.error(f"Image preprocessing error: {e}")
164
- return None
165
 
166
  def analyze_image(self, image):
167
  """Analyze image for defects"""
@@ -198,6 +187,20 @@ class ImageAnalyzer:
198
  return None
199
 
200
  @st.cache_data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  def get_groq_response(query: str, context: str) -> str:
202
  """Get response from Groq LLM with caching"""
203
  try:
 
148
  logger.error(f"Model initialization error: {e}")
149
  return None
150
 
 
151
  def preprocess_image(self, image_bytes):
152
  """Preprocess image for model input"""
153
+ return _cached_preprocess_image(image_bytes)
 
 
 
 
 
 
 
 
 
 
154
 
155
  def analyze_image(self, image):
156
  """Analyze image for defects"""
 
187
  return None
188
 
189
  @st.cache_data
190
+ def _cached_preprocess_image(image_bytes):
191
+ """Cached version of image preprocessing"""
192
+ try:
193
+ image = Image.open(image_bytes)
194
+ if image.mode != 'RGB':
195
+ image = image.convert('RGB')
196
+
197
+ width, height = 224, 224
198
+ image = image.resize((width, height), Image.Resampling.LANCZOS)
199
+ return image
200
+ except Exception as e:
201
+ logger.error(f"Image preprocessing error: {e}")
202
+ return None
203
+
204
  def get_groq_response(query: str, context: str) -> str:
205
  """Get response from Groq LLM with caching"""
206
  try: