Spaces:
Sleeping
Sleeping
Commit ·
bd276da
1
Parent(s): 65e0e3a
fix
Browse files
app.py
CHANGED
|
@@ -1,27 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
'
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
tag_name = item['tagName']
|
| 21 |
-
probability = item['probability']
|
| 22 |
-
output_dict[tag_name] = probability
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|