Spaces:
Runtime error
Runtime error
syurein
commited on
Commit
·
d4c44f1
1
Parent(s):
9c1c467
APIきーset
Browse files
app.py
CHANGED
|
@@ -1007,12 +1007,14 @@ async def mosaic_face(file: UploadFile = File(...)):
|
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
-
async def
|
| 1011 |
image_path = "./temp_image.jpg"
|
| 1012 |
# アップロードされた画像を保存
|
| 1013 |
with open(image_path, "wb") as buffer:
|
| 1014 |
buffer.write(await file.read())
|
| 1015 |
-
|
|
|
|
|
|
|
| 1016 |
return {"danger":danger_level}
|
| 1017 |
|
| 1018 |
|
|
@@ -1026,12 +1028,14 @@ async def classify_image_llm2(file: UploadFile = File(...)):
|
|
| 1026 |
|
| 1027 |
# LLMを使用して画像を分類するエンドポイント
|
| 1028 |
@app.post("/classify-image-llm/")
|
| 1029 |
-
async def classify_image_llm(file: UploadFile = File(...)):
|
| 1030 |
image_path = "./temp_image.jpg"
|
| 1031 |
# アップロードされた画像を保存
|
| 1032 |
with open(image_path, "wb") as buffer:
|
| 1033 |
buffer.write(await file.read())
|
| 1034 |
-
|
|
|
|
|
|
|
| 1035 |
return {"danger":danger_level}
|
| 1036 |
|
| 1037 |
'''
|
|
|
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
+
async def classify_image_llm(file: UploadFile = File(...), api_key: str = None):
|
| 1011 |
image_path = "./temp_image.jpg"
|
| 1012 |
# アップロードされた画像を保存
|
| 1013 |
with open(image_path, "wb") as buffer:
|
| 1014 |
buffer.write(await file.read())
|
| 1015 |
+
if not api_key:
|
| 1016 |
+
api_key = os.getenv('GEMINI_API_KEY')
|
| 1017 |
+
danger_level = ObjectDetector(API_KEY=api_key).detect_danger_level(image_path)
|
| 1018 |
return {"danger":danger_level}
|
| 1019 |
|
| 1020 |
|
|
|
|
| 1028 |
|
| 1029 |
# LLMを使用して画像を分類するエンドポイント
|
| 1030 |
@app.post("/classify-image-llm/")
|
| 1031 |
+
async def classify_image_llm(file: UploadFile = File(...), api_key: str = None):
|
| 1032 |
image_path = "./temp_image.jpg"
|
| 1033 |
# アップロードされた画像を保存
|
| 1034 |
with open(image_path, "wb") as buffer:
|
| 1035 |
buffer.write(await file.read())
|
| 1036 |
+
if not api_key:
|
| 1037 |
+
api_key = os.getenv('GEMINI_API_KEY')
|
| 1038 |
+
danger_level = ObjectDetector(API_KEY=api_key).detect_danger_level(image_path)
|
| 1039 |
return {"danger":danger_level}
|
| 1040 |
|
| 1041 |
'''
|