Spaces:
Running
Running
syurein
commited on
Commit
·
3ae57fa
1
Parent(s):
709c305
とりあえず
Browse files- app.py +10 -8
- requirements.txt +1 -1
app.py
CHANGED
@@ -19,7 +19,7 @@ import numpy as np
|
|
19 |
import cv2
|
20 |
from LLM_package import ObjectDetector,GeminiInference
|
21 |
import pycocotools.mask as mask_util
|
22 |
-
import insightface
|
23 |
from fastapi import FastAPI, File, UploadFile, Form
|
24 |
from fastapi.middleware.cors import CORSMiddleware
|
25 |
from fastapi.responses import FileResponse, HTMLResponse
|
@@ -835,7 +835,7 @@ async def create_mask_sum(image: UploadFile = File(...), risk_level: int = Form(
|
|
835 |
return FileResponse(output_path)
|
836 |
|
837 |
# カスケードファイルの読み込み (顔検出)
|
838 |
-
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
839 |
|
840 |
def apply_mosaic(image, x, y, w, h, mosaic_level=15):
|
841 |
""" 指定範囲にモザイク処理を適用 """
|
@@ -844,7 +844,7 @@ def apply_mosaic(image, x, y, w, h, mosaic_level=15):
|
|
844 |
face = cv2.resize(face, (w, h), interpolation=cv2.INTER_NEAREST)
|
845 |
image[y:y+h, x:x+w] = face
|
846 |
return image
|
847 |
-
|
848 |
@app.post("/mosaic_face")
|
849 |
async def mosaic_face(file: UploadFile = File(...)):
|
850 |
# 画像ファイルを読み込み
|
@@ -870,7 +870,7 @@ async def mosaic_face(file: UploadFile = File(...)):
|
|
870 |
|
871 |
|
872 |
|
873 |
-
|
874 |
|
875 |
|
876 |
|
@@ -961,7 +961,7 @@ def read_image(file: UploadFile):
|
|
961 |
if image.shape[2] == 4: # Remove alpha channel if present
|
962 |
image = image[:, :, :3]
|
963 |
return cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
964 |
-
|
965 |
# Function to extract face embeddings and bounding boxes from an image
|
966 |
def get_face_data(image):
|
967 |
# Load InsightFace model
|
@@ -975,7 +975,7 @@ def get_face_data(image):
|
|
975 |
return embeddings, bboxes, image
|
976 |
else:
|
977 |
return None, None, image
|
978 |
-
|
979 |
# Function to apply mosaic to a specific region in an image
|
980 |
def apply_mosaic(image, bbox, mosaic_size=10):
|
981 |
x, y, w, h = int(bbox[0]), int(bbox[1]), int(bbox[2] - bbox[0]), int(bbox[3] - bbox[1])
|
@@ -988,6 +988,7 @@ def apply_mosaic(image, bbox, mosaic_size=10):
|
|
988 |
return image
|
989 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
990 |
from io import BytesIO #
|
|
|
991 |
@app.post("/mosaic_faces")
|
992 |
async def mosaic_faces(reference_image: UploadFile = File(...), test_image: UploadFile = File(...)):
|
993 |
try:
|
@@ -1022,9 +1023,10 @@ async def mosaic_faces(reference_image: UploadFile = File(...), test_image: Uplo
|
|
1022 |
|
1023 |
except Exception as e:
|
1024 |
raise HTTPException(status_code=500, detail=str(e))
|
1025 |
-
|
1026 |
@app.get("/", response_class=HTMLResponse)
|
1027 |
-
async def read_root():
|
|
|
1028 |
return templates.TemplateResponse("index.html", {"request": request})
|
1029 |
|
1030 |
|
|
|
19 |
import cv2
|
20 |
from LLM_package import ObjectDetector,GeminiInference
|
21 |
import pycocotools.mask as mask_util
|
22 |
+
#import insightface
|
23 |
from fastapi import FastAPI, File, UploadFile, Form
|
24 |
from fastapi.middleware.cors import CORSMiddleware
|
25 |
from fastapi.responses import FileResponse, HTMLResponse
|
|
|
835 |
return FileResponse(output_path)
|
836 |
|
837 |
# カスケードファイルの読み込み (顔検出)
|
838 |
+
#face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
839 |
|
840 |
def apply_mosaic(image, x, y, w, h, mosaic_level=15):
|
841 |
""" 指定範囲にモザイク処理を適用 """
|
|
|
844 |
face = cv2.resize(face, (w, h), interpolation=cv2.INTER_NEAREST)
|
845 |
image[y:y+h, x:x+w] = face
|
846 |
return image
|
847 |
+
'''
|
848 |
@app.post("/mosaic_face")
|
849 |
async def mosaic_face(file: UploadFile = File(...)):
|
850 |
# 画像ファイルを読み込み
|
|
|
870 |
|
871 |
|
872 |
|
873 |
+
'''
|
874 |
|
875 |
|
876 |
|
|
|
961 |
if image.shape[2] == 4: # Remove alpha channel if present
|
962 |
image = image[:, :, :3]
|
963 |
return cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
964 |
+
'''
|
965 |
# Function to extract face embeddings and bounding boxes from an image
|
966 |
def get_face_data(image):
|
967 |
# Load InsightFace model
|
|
|
975 |
return embeddings, bboxes, image
|
976 |
else:
|
977 |
return None, None, image
|
978 |
+
'''
|
979 |
# Function to apply mosaic to a specific region in an image
|
980 |
def apply_mosaic(image, bbox, mosaic_size=10):
|
981 |
x, y, w, h = int(bbox[0]), int(bbox[1]), int(bbox[2] - bbox[0]), int(bbox[3] - bbox[1])
|
|
|
988 |
return image
|
989 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
990 |
from io import BytesIO #
|
991 |
+
'''
|
992 |
@app.post("/mosaic_faces")
|
993 |
async def mosaic_faces(reference_image: UploadFile = File(...), test_image: UploadFile = File(...)):
|
994 |
try:
|
|
|
1023 |
|
1024 |
except Exception as e:
|
1025 |
raise HTTPException(status_code=500, detail=str(e))
|
1026 |
+
'''
|
1027 |
@app.get("/", response_class=HTMLResponse)
|
1028 |
+
async def read_root(request: Request):
|
1029 |
+
|
1030 |
return templates.TemplateResponse("index.html", {"request": request})
|
1031 |
|
1032 |
|
requirements.txt
CHANGED
@@ -72,5 +72,5 @@ uvicorn==0.32.0
|
|
72 |
zipp==3.20.2
|
73 |
supervision
|
74 |
onnxruntime
|
75 |
-
|
76 |
dotenv
|
|
|
72 |
zipp==3.20.2
|
73 |
supervision
|
74 |
onnxruntime
|
75 |
+
google-genai
|
76 |
dotenv
|