hyunjunian commited on
Commit
bd276da
·
1 Parent(s): 65e0e3a
Files changed (1) hide show
  1. app.py +26 -19
app.py CHANGED
@@ -1,27 +1,34 @@
1
  import gradio as gr
2
  import requests
3
 
4
- def greet(image):
5
- with open(image, 'rb') as f:
6
- r = requests.post(
7
- 'https://6a051cv20250210-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/29f565b7-4710-47a5-8a47-723048ff7ec9/classify/iterations/Iteration2/image',
8
- headers={
9
- 'Prediction-Key': '8uyKSiqRNbG2JLdMjI8AeOzADtORP3jRh5klqQr0JsJrBBt7x7iPJQQJ99BBACYeBjFXJ3w3AAAIACOGHg4K',
10
- 'Content-Type': 'application/octet-stream',
11
- },
12
- data=f.read(),
13
- )
14
- if r.status_code != 200:
15
- return {'확인불가': 1.0}
 
16
 
17
- output_dict = {}
 
18
 
19
- for item in r.json()['predictions']:
20
- tag_name = item['tagName']
21
- probability = item['probability']
22
- output_dict[tag_name] = probability
23
 
24
- return output_dict
 
 
 
25
 
26
- demo = gr.Interface(fn=greet, inputs=gr.Image(label="Input Image Component", type="filepath"), outputs="label")
 
 
 
 
 
27
  demo.launch()
 
1
  import gradio as gr
2
  import requests
3
 
4
+ def abnormal(image):
5
+ if (image is None) or (image == ''):
6
+ return {'이미지가 제공되지 않았습니다.': 1.0}
7
+ try:
8
+ with open(image, 'rb') as f:
9
+ r = requests.post(
10
+ 'https://6a051cv20250210-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/29f565b7-4710-47a5-8a47-723048ff7ec9/classify/iterations/Iteration2/image',
11
+ headers={
12
+ 'Prediction-Key': '8uyKSiqRNbG2JLdMjI8AeOzADtORP3jRh5klqQr0JsJrBBt7x7iPJQQJ99BBACYeBjFXJ3w3AAAIACOGHg4K',
13
+ 'Content-Type': 'application/octet-stream',
14
+ },
15
+ data=f.read(),
16
+ )
17
 
18
+ if r.status_code != 200:
19
+ return {'확인불가': 1.0}
20
 
21
+ output_dict = {}
 
 
 
22
 
23
+ for item in r.json()['predictions']:
24
+ tag_name = item['tagName']
25
+ probability = item['probability']
26
+ output_dict[tag_name] = probability
27
 
28
+ return output_dict
29
+
30
+ except Exception as e:
31
+ return {[str(e)]: 1.0}
32
+
33
+ demo = gr.Interface(fn=abnormal, inputs=gr.Image(label="Input Image Component", type="filepath"), outputs="label")
34
  demo.launch()