leedoming commited on
Commit
7d37333
·
verified ·
1 Parent(s): 471be17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -8,9 +8,13 @@ import time
8
  import json
9
  import numpy as np
10
  import cv2
11
- from inference_sdk import InferenceHTTPClient, HTTPCallErrorError
12
  import matplotlib.pyplot as plt
13
- import base64
 
 
 
 
14
 
15
  # Load model and tokenizer
16
  @st.cache_resource
@@ -47,7 +51,7 @@ if api_key:
47
  # 이미지를 base64로 인코딩
48
  encoded_image = base64.b64encode(image_data).decode('utf-8')
49
 
50
- # 원본 이미지 로드 (여기로 이동)
51
  image = cv2.imread(image_path)
52
  image = cv2.resize(image, (800, 600))
53
  mask = np.zeros(image.shape, dtype=np.uint8)
@@ -55,9 +59,8 @@ if api_key:
55
  try:
56
  # Roboflow API 호출
57
  results = CLIENT.infer(encoded_image, model_id="closet/1")
58
- except HTTPCallErrorError as api_error:
59
- st.error(f"API Error: {api_error.description}")
60
- st.error(f"API Message: {api_error.api_message}")
61
  return Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
62
 
63
  if 'predictions' in results:
 
8
  import json
9
  import numpy as np
10
  import cv2
11
+ from inference_sdk import InferenceHTTPClient
12
  import matplotlib.pyplot as plt
13
+ import base64
14
+
15
+ # 오류 처리를 위한 예외 클래스 정의
16
+ class APIError(Exception):
17
+ pass
18
 
19
  # Load model and tokenizer
20
  @st.cache_resource
 
51
  # 이미지를 base64로 인코딩
52
  encoded_image = base64.b64encode(image_data).decode('utf-8')
53
 
54
+ # 원본 이미지 로드
55
  image = cv2.imread(image_path)
56
  image = cv2.resize(image, (800, 600))
57
  mask = np.zeros(image.shape, dtype=np.uint8)
 
59
  try:
60
  # Roboflow API 호출
61
  results = CLIENT.infer(encoded_image, model_id="closet/1")
62
+ except Exception as api_error:
63
+ st.error(f"API Error: {str(api_error)}")
 
64
  return Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
65
 
66
  if 'predictions' in results: