Spaces:
Runtime error
Runtime error
syurein
commited on
Commit
·
124b732
1
Parent(s):
2443b6b
クラスの定義
Browse files- detector.py +36 -0
detector.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from LLM_package import GeminiInference
|
| 3 |
+
import json
|
| 4 |
+
class ObjectDetector:
|
| 5 |
+
def __init__(self, model_path):
|
| 6 |
+
self.model = GeminiInference()
|
| 7 |
+
self.prompt_objects=None
|
| 8 |
+
self.text=None
|
| 9 |
+
self.prompt= f"""
|
| 10 |
+
Detect all {self.prompt_objects} in the image. The box_2d should be [ymin, xmin, ymax, xmax] normalized to 0-1000.
|
| 11 |
+
Please provide the response as a JSON array of objects, where each object has a 'label' and 'box_2d' field.
|
| 12 |
+
Example:
|
| 13 |
+
[
|
| 14 |
+
{{"label": "face", "box_2d": [100, 200, 300, 400]}},
|
| 15 |
+
{{"label": "license_plate", "box_2d": [500, 600, 700, 800]}}
|
| 16 |
+
]
|
| 17 |
+
"""
|
| 18 |
+
def detect_objects(self, image_path):
|
| 19 |
+
detected_objects_norm_0_1= self.model.parse_response(self.model.get_response(image_path, self.prompt)) return detected_objects_norm_0_1
|
| 20 |
+
def detect_danger_level(self, image_path):
|
| 21 |
+
"""
|
| 22 |
+
Detects the danger level of the image.
|
| 23 |
+
"""
|
| 24 |
+
analysis_prompt = f"""
|
| 25 |
+
画像の個人情報漏洩リスクを分析し、厳密にJSON形式で返答してください。なおこの時、資料があれば、資料を参考にしてください:
|
| 26 |
+
{{
|
| 27 |
+
"risk_level": "high|medium|low",
|
| 28 |
+
"risk_reason": "リスクの具体的理由",
|
| 29 |
+
"objects_to_remove": ["消去すべきオブジェクトリスト(英語で、例: 'face', 'license_plate')"]
|
| 30 |
+
}}
|
| 31 |
+
<資料>
|
| 32 |
+
{self.text if self.text else "なし"}
|
| 33 |
+
</資料>
|
| 34 |
+
"""
|
| 35 |
+
response = json.loads(self.model.get_response_text(image_path, analysis_prompt))
|
| 36 |
+
return response
|