前提
現在Streamlit shaingにてazure computer vision apiを用いたアップロードされた
画像の位置情報を検出するアプリを作成してるのですが、画像をアップロードした際
、画像の位置情報を取得する時にに以下のエラーメッセージが発生しました。
実現したいこと
- ConnectionErrorを解決し、画像の位置情報を取得できるようにする
発生している問題・エラーメッセージ
msrest.exceptions.ClientRequestError: Error occurred in request., ConnectionError: HTTPSConnectionPool(host='computer vision apiのエンドポイント', port=443): Max retries exceeded with url: /vision/v3.2/detect?model-version=latest (Caused by NewConnectionError ('<urllib3.connection.HTTPSConnection object at 0x7fee51237b10>: Failed to establish a new connection: [Errno -2] Name or service not known'))
該当のソースコード
認証キーとエンドポイントはstreamlit sharingのsecretにて設定しています。
python:object_detection_apri.py
1subscription_key = st.secrets["AzureApiKey"]["KEY"] 2endpoint = st.secrets["AzureApiKey"]["ENDPOINT"] 3 4#クライアントを認証(apiを使えるかどうかの認証) 5computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key)) 6 7subscription_key = st.secrets["AzureApiKey"]["KEY"] 8endpoint = st.secrets["AzureApiKey"]["ENDPOINT"] 9 10#オブジェクトの位置と情報 11def detect_objects(filepath): 12 local_image = open(filepath, "rb") 13 14 detect_objects_results = computervision_client.detect_objects(local_image) 15 objects = detect_objects_results.objects 16 return objects 17 18. 19. 20. 21#ファイルアップロード機能 22uploaded_file = st.file_uploader('Choose an image...', type=['jpg', 'png']) 23if uploaded_file is not None: 24 #画像ファイルにalpha値が含まれているケースを回避するためrgb変換 25 img = Image.open(uploaded_file).convert('RGB') 26 27 #関数でファイルパスを指定するため読み込んだ画像を特定のフォルダに保存する 28 img_path = f'img/{uploaded_file.name}' 29 img.save(img_path) 30 objects = detect_objects(img_path) 31
ご指摘宜しくお願い致します。
あなたの回答
tips
プレビュー