iT邦幫忙

0

azure內容仲裁-google雲端硬碟裡面的圖片

  • 分享至 

  • xImage

小弟我在做利用azure的內容仲裁api去識別google雲端硬碟資料夾11裡是否具有言犯性或不應出現的影像,如果我直接貼單張圖片的url會成功但改成讀取資料夾時就會呈現最後一張圖那樣請各位大神幫幫我下方是我程式碼
https://ithelp.ithome.com.tw/upload/images/20230524/20155809KIShnnc9t7.png
import os
import requests
from PIL import Image
from io import BytesIO
import http.client, urllib.request, urllib.parse, urllib.error
import json

apikey = "ac03a2e65462430c86f772320f5f64e8"
Host = 'https://re-content4.cognitiveservices.azure.com/'

image_folder_path = "/content/drive/MyDrive/11" # 替換為您的圖片資料夾路徑

headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': apikey
}

params = urllib.parse.urlencode({
'CacheImage': '1',
})

parsed_url = urllib.parse.urlparse(Host)
conn = http.client.HTTPSConnection(parsed_url.netloc)

for filename in os.listdir(image_folder_path):
image_path = os.path.join(image_folder_path, filename)
image = Image.open(image_path)
image.show()

with open(image_path, 'rb') as image_file:
    image_data = image_file.read()

body = {
    "DataRepresentation": "URL",
    "Value": "https://drive.google.com/your_image_link",
    "ContentModeration": {
        "AdultClassifier": "True",
        "RacyClassifier": "True",
        "GoryClassifier": "True",
        "UnderageClassifier": "True"
    }
}

conn = http.client.HTTPSConnection(parsed_url.netloc)
try:
    conn.request("POST", "/contentmoderator/moderate/v1.0/ProcessImage/Evaluate?%s" % params, json.dumps(body, ensure_ascii=False).encode('utf-8'), headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    print()

    
    img_evaluate = json.loads(data)
    print("是否具有言犯性或不應出現的影像:" + str(img_evaluate["IsImageAdultClassified"]))
    print("是否具有色情內容:" + str(img_evaluate["IsImageRacyClassified"]))

    conn.close()
except Exception as e:
  print(str(e))

https://ithelp.ithome.com.tw/upload/images/20230524/201558090SvAw7Ap5Q.png
https://ithelp.ithome.com.tw/upload/images/20230524/2015580977HidFgG6l.png

黃彥儒 iT邦高手 1 級 ‧ 2023-05-24 16:46:27 檢舉
那個Key是真的能用的嗎?
4A9G0093 iT邦新手 5 級 ‧ 2023-05-24 17:02:08 檢舉
是的在api介面做send是他跑是ok
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答