Spaces:
Running
Running
Commit
·
cd1b549
1
Parent(s):
720bf8c
fix
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
# def abnormal(image):
|
5 |
# if (image is None) or (image == ''):
|
@@ -35,15 +36,18 @@ import requests
|
|
35 |
|
36 |
def abnormal_stream(image):
|
37 |
try:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
47 |
|
48 |
if r.status_code != 200:
|
49 |
return {'확인불가': 1.0, r.status_code: 0.0, r.text: 0.0}
|
@@ -58,12 +62,12 @@ def abnormal_stream(image):
|
|
58 |
return output_dict
|
59 |
|
60 |
except Exception as e:
|
61 |
-
return {
|
62 |
|
63 |
with gr.Blocks() as demo:
|
64 |
with gr.Row():
|
65 |
with gr.Column():
|
66 |
-
input_img = gr.Image(sources=["webcam"], type="
|
67 |
with gr.Column():
|
68 |
output_label = gr.Label()
|
69 |
dep = input_img.stream(abnormal_stream, [input_img], [output_label])
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from io import BytesIO
|
4 |
|
5 |
# def abnormal(image):
|
6 |
# if (image is None) or (image == ''):
|
|
|
36 |
|
37 |
def abnormal_stream(image):
|
38 |
try:
|
39 |
+
byte_io = BytesIO()
|
40 |
+
image.save(byte_io, 'png')
|
41 |
+
byte_io.seek(0)
|
42 |
+
|
43 |
+
r = requests.post(
|
44 |
+
'https://6a051cv20250210-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/29f565b7-4710-47a5-8a47-723048ff7ec9/classify/iterations/Iteration2/image',
|
45 |
+
headers={
|
46 |
+
'Prediction-Key': '8uyKSiqRNbG2JLdMjI8AeOzADtORP3jRh5klqQr0JsJrBBt7x7iPJQQJ99BBACYeBjFXJ3w3AAAIACOGHg4K',
|
47 |
+
'Content-Type': 'image/png',
|
48 |
+
},
|
49 |
+
data=byte_io,
|
50 |
+
)
|
51 |
|
52 |
if r.status_code != 200:
|
53 |
return {'확인불가': 1.0, r.status_code: 0.0, r.text: 0.0}
|
|
|
62 |
return output_dict
|
63 |
|
64 |
except Exception as e:
|
65 |
+
return {str(e): 1.0}
|
66 |
|
67 |
with gr.Blocks() as demo:
|
68 |
with gr.Row():
|
69 |
with gr.Column():
|
70 |
+
input_img = gr.Image(sources=["webcam"], type="pil")
|
71 |
with gr.Column():
|
72 |
output_label = gr.Label()
|
73 |
dep = input_img.stream(abnormal_stream, [input_img], [output_label])
|