petter2025 commited on
Commit
0eb085a
·
verified ·
1 Parent(s): faa8d15

Create image_detector.py

Browse files
Files changed (1) hide show
  1. image_detector.py +48 -0
image_detector.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from typing import Dict, Any
3
+ from agentic_reliability_framework.runtime.agents.base import BaseAgent, AgentSpecialization
4
+ from ai_event import AIEvent
5
+
6
+ logger = logging.getLogger(__name__)
7
+
8
+ class ImageQualityDetector(BaseAgent):
9
+ """
10
+ Detects potential quality issues in generated images.
11
+ Currently uses generation time as a proxy; can be extended with CLIP or aesthetic models.
12
+ """
13
+
14
+ def __init__(self):
15
+ super().__init__(AgentSpecialization.DETECTIVE)
16
+ self._thresholds = {'generation_time': 2.0} # seconds
17
+
18
+ async def analyze(self, event: AIEvent) -> Dict[str, Any]:
19
+ """
20
+ Analyze image generation event.
21
+ Expects `retrieval_scores` to contain [retrieval_score, generation_time].
22
+ """
23
+ # Default values
24
+ gen_time = 1.0
25
+ if event.retrieval_scores and len(event.retrieval_scores) > 1:
26
+ gen_time = event.retrieval_scores[1]
27
+
28
+ flags = []
29
+ if gen_time > self._thresholds['generation_time']:
30
+ flags.append('slow_generation')
31
+
32
+ # Confidence inversely related to generation time (heuristic)
33
+ confidence = max(0, 1.0 - (gen_time / 5.0))
34
+
35
+ return {
36
+ 'specialization': 'image_quality',
37
+ 'confidence': confidence,
38
+ 'findings': {
39
+ 'flags': flags,
40
+ 'generation_time': gen_time,
41
+ 'quality_issues': flags
42
+ },
43
+ 'recommendations': [
44
+ "Use a simpler prompt",
45
+ "Upgrade hardware",
46
+ "Reduce resolution"
47
+ ] if flags else []
48
+ }