petter2025 commited on
Commit
c35dc07
·
verified ·
1 Parent(s): 1862ca1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -200,11 +200,11 @@ async def handle_text(task_type, prompt):
200
  return {"error": str(e)}
201
 
202
  async def handle_image(prompt):
203
- """Handle image generation and quality analysis."""
204
  global last_task_category
205
  last_task_category = "image"
206
  if image_pipe is None:
207
- return {"error": "Image model not loaded"}, None
208
  try:
209
  import time
210
  start = time.time()
@@ -233,15 +233,15 @@ async def handle_image(prompt):
233
  latency_ms=gen_time * 1000
234
  )
235
  quality_result = await image_quality_detector.analyze(event)
236
- return {
237
- "image": image,
238
  "generation_time": gen_time,
239
  "retrieval_score": retrieval_score,
240
  "quality_detection": quality_result
241
  }
 
242
  except Exception as e:
243
  logger.error(f"Image task error: {e}")
244
- return {"error": str(e)}, None
245
 
246
  async def handle_audio(audio_file):
247
  """Handle audio transcription and quality analysis."""
@@ -302,10 +302,10 @@ async def read_iot_sensors(fault_type):
302
  if len(iot_history) > 100:
303
  iot_history.pop(0)
304
 
305
- # Create IoTEvent
306
  event = IoTEvent(
307
  timestamp=datetime.utcnow(),
308
- component="robotic_arm",
309
  service_mesh="factory",
310
  latency_p99=0,
311
  error_rate=0.0,
 
200
  return {"error": str(e)}
201
 
202
  async def handle_image(prompt):
203
+ """Handle image generation and quality analysis. Returns (image, json_data)."""
204
  global last_task_category
205
  last_task_category = "image"
206
  if image_pipe is None:
207
+ return None, {"error": "Image model not loaded"}
208
  try:
209
  import time
210
  start = time.time()
 
233
  latency_ms=gen_time * 1000
234
  )
235
  quality_result = await image_quality_detector.analyze(event)
236
+ json_data = {
 
237
  "generation_time": gen_time,
238
  "retrieval_score": retrieval_score,
239
  "quality_detection": quality_result
240
  }
241
+ return image, json_data
242
  except Exception as e:
243
  logger.error(f"Image task error: {e}")
244
+ return None, {"error": str(e)}
245
 
246
  async def handle_audio(audio_file):
247
  """Handle audio transcription and quality analysis."""
 
302
  if len(iot_history) > 100:
303
  iot_history.pop(0)
304
 
305
+ # Create IoTEvent with valid component name (hyphens allowed, underscores not allowed)
306
  event = IoTEvent(
307
  timestamp=datetime.utcnow(),
308
+ component="robotic-arm", # changed from 'robotic_arm'
309
  service_mesh="factory",
310
  latency_p99=0,
311
  error_rate=0.0,