Spaces:
Sleeping
Sleeping
syurein
commited on
Commit
·
6c31327
1
Parent(s):
9cf613c
シーンの機能実装
Browse files- LLM_package.py +4 -1
- app.py +9 -4
LLM_package.py
CHANGED
@@ -70,6 +70,7 @@ class ObjectDetector:
|
|
70 |
self.model = GeminiInference(API_KEY)
|
71 |
self.prompt_objects=None
|
72 |
self.text=None
|
|
|
73 |
|
74 |
def detect_objects(self, image_path):
|
75 |
self.prompt= f"""
|
@@ -89,12 +90,14 @@ class ObjectDetector:
|
|
89 |
"""
|
90 |
def detect_auto(self, image_path):
|
91 |
analysis_prompt = f"""
|
92 |
-
画像の個人情報漏洩リスクを分析し、厳密にJSON
|
|
|
93 |
{{
|
94 |
"risk_level":0~100,
|
95 |
"risk_reason": "リスクの具体的理由",
|
96 |
"objects_to_remove": ["消去すべきオブジェクトリスト(英語で、例: 'face', 'license_plate')"]
|
97 |
}}
|
|
|
98 |
<資料>
|
99 |
{self.text if self.text else "なし"}
|
100 |
</資料>
|
|
|
70 |
self.model = GeminiInference(API_KEY)
|
71 |
self.prompt_objects=None
|
72 |
self.text=None
|
73 |
+
self.scene=None
|
74 |
|
75 |
def detect_objects(self, image_path):
|
76 |
self.prompt= f"""
|
|
|
90 |
"""
|
91 |
def detect_auto(self, image_path):
|
92 |
analysis_prompt = f"""
|
93 |
+
画像の個人情報漏洩リスクを分析し、厳密にJSON形式で返答してください。なおこの時、資料があれば、資料を参考にしてください。またこの際にその写真のシーンの情報もあれば参考にして動的に
|
94 |
+
消去するオブジェクトを変化させてください:
|
95 |
{{
|
96 |
"risk_level":0~100,
|
97 |
"risk_reason": "リスクの具体的理由",
|
98 |
"objects_to_remove": ["消去すべきオブジェクトリスト(英語で、例: 'face', 'license_plate')"]
|
99 |
}}
|
100 |
+
<写真を撮ったシーンの情報>{self.scene if self.scene else "なし"}
|
101 |
<資料>
|
102 |
{self.text if self.text else "なし"}
|
103 |
</資料>
|
app.py
CHANGED
@@ -298,7 +298,7 @@ def llm_to_process_image_simple(risk_level, image_path, point1, point2, threshol
|
|
298 |
|
299 |
|
300 |
|
301 |
-
async def llm_to_process_image_simple_auto(risk_level, image_path, point1, point2, thresholds=None):
|
302 |
print(f"リスクレベル: {risk_level}, 画像パス: {image_path}, point1: {point1}, point2: {point2}, しきい値: {thresholds}")
|
303 |
print(f"point1, point2: {point1}, {point2}")
|
304 |
|
@@ -306,7 +306,7 @@ async def llm_to_process_image_simple_auto(risk_level, image_path, point1, point
|
|
306 |
|
307 |
# 画像処理のロジックを追加
|
308 |
Objectdetector = ObjectDetector(API_KEY=GEMINI_API_KEY)
|
309 |
-
|
310 |
# デバッグ用の画像パスを定義。保存時にファイル名として使われます。
|
311 |
debug_image_name = "masked_image.jpg" # デバッグ画像名を具体的に
|
312 |
debug_image_path = os.path.join("./saved_images", debug_image_name)
|
@@ -324,7 +324,7 @@ async def llm_to_process_image_simple_auto(risk_level, image_path, point1, point
|
|
324 |
all_content = "\n\n---\n\n".join([doc['cleaned_html_content'] for doc in personal_breach_docs])
|
325 |
Objectdetector.text = all_content
|
326 |
print(f"Webスクレイピングの結果をコンテキストとして設定しました。文字数: {len(all_content)}")
|
327 |
-
|
328 |
# Webスクレイピングの結果を資料として渡し、リスク分析を実行
|
329 |
response = Objectdetector.detect_auto(image_path)
|
330 |
print(f"削除対象オブジェクト: {response['objects_to_remove']}")
|
@@ -1112,7 +1112,10 @@ async def analyze(
|
|
1112 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
1113 |
unique_id = uuid.uuid4().hex
|
1114 |
input_path = save_image(file.file, f"input_{timestamp}_{unique_id}.jpg")
|
1115 |
-
|
|
|
|
|
|
|
1116 |
output_path = f"./output_simple_lama_{timestamp}_{unique_id}.jpg"
|
1117 |
print(f'point1,point2: {point1},{point2}') # 消去したくない範囲
|
1118 |
|
@@ -1128,6 +1131,8 @@ async def analyze(
|
|
1128 |
except Exception as e:
|
1129 |
print(f"リクエスト処理エラー: {str(e)}")
|
1130 |
raise HTTPException(status_code=500, detail="内部サーバーエラー")
|
|
|
|
|
1131 |
@app.post("/create-mask-and-inpaint-sum-llm-simple")
|
1132 |
async def create_mask_sum2(image: UploadFile = File(...), risk_level: int = Form(...),
|
1133 |
x1: float = Form(...),
|
|
|
298 |
|
299 |
|
300 |
|
301 |
+
async def llm_to_process_image_simple_auto(risk_level, image_path, point1, point2, thresholds=None, scene=''):
|
302 |
print(f"リスクレベル: {risk_level}, 画像パス: {image_path}, point1: {point1}, point2: {point2}, しきい値: {thresholds}")
|
303 |
print(f"point1, point2: {point1}, {point2}")
|
304 |
|
|
|
306 |
|
307 |
# 画像処理のロジックを追加
|
308 |
Objectdetector = ObjectDetector(API_KEY=GEMINI_API_KEY)
|
309 |
+
Objectdetector.scene = scene # シーン情報を設定
|
310 |
# デバッグ用の画像パスを定義。保存時にファイル名として使われます。
|
311 |
debug_image_name = "masked_image.jpg" # デバッグ画像名を具体的に
|
312 |
debug_image_path = os.path.join("./saved_images", debug_image_name)
|
|
|
324 |
all_content = "\n\n---\n\n".join([doc['cleaned_html_content'] for doc in personal_breach_docs])
|
325 |
Objectdetector.text = all_content
|
326 |
print(f"Webスクレイピングの結果をコンテキストとして設定しました。文字数: {len(all_content)}")
|
327 |
+
|
328 |
# Webスクレイピングの結果を資料として渡し、リスク分析を実行
|
329 |
response = Objectdetector.detect_auto(image_path)
|
330 |
print(f"削除対象オブジェクト: {response['objects_to_remove']}")
|
|
|
1112 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
1113 |
unique_id = uuid.uuid4().hex
|
1114 |
input_path = save_image(file.file, f"input_{timestamp}_{unique_id}.jpg")
|
1115 |
+
if mode== 'auto':
|
1116 |
+
mask_path,response =await llm_to_process_image_simple_auto(risk_level, input_path, point1, point2,thresholds=thresholds)
|
1117 |
+
else:
|
1118 |
+
mask_path = llm_to_process_image_simple(risk_level, input_path, point1, point2, thresholds=thresholds)
|
1119 |
output_path = f"./output_simple_lama_{timestamp}_{unique_id}.jpg"
|
1120 |
print(f'point1,point2: {point1},{point2}') # 消去したくない範囲
|
1121 |
|
|
|
1131 |
except Exception as e:
|
1132 |
print(f"リクエスト処理エラー: {str(e)}")
|
1133 |
raise HTTPException(status_code=500, detail="内部サーバーエラー")
|
1134 |
+
|
1135 |
+
|
1136 |
@app.post("/create-mask-and-inpaint-sum-llm-simple")
|
1137 |
async def create_mask_sum2(image: UploadFile = File(...), risk_level: int = Form(...),
|
1138 |
x1: float = Form(...),
|