Spaces:
Running
Running
Commit
·
7262063
1
Parent(s):
faf0719
rollback
Browse files- app.py +10 -20
- requirements.txt +0 -1
app.py
CHANGED
@@ -1,19 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
from io import BytesIO
|
4 |
-
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
|
5 |
-
from msrest.authentication import ApiKeyCredentials
|
6 |
-
|
7 |
-
classification_prediction_endpoint = "https://6b034cv20250210-prediction.cognitiveservices.azure.com/"
|
8 |
-
classification_prediction_key = "EAqbiKHt9sYSwFiO7U1NUBngdvnBoJRmd3ZLl0V0XzKkBbzibzPoJQQJ99BBACYeBjFXJ3w3AAAIACOGYNGQ"
|
9 |
-
classification_project_id = "b632b81b-f8d4-48ed-a74d-022aab130c5d"
|
10 |
-
classification_publish_iteration_name = "Iteration4"
|
11 |
-
|
12 |
-
classification_credentials = ApiKeyCredentials(in_headers={"Prediction-key": classification_prediction_key})
|
13 |
-
classification_predictor = CustomVisionPredictionClient(
|
14 |
-
endpoint=classification_prediction_endpoint,
|
15 |
-
credentials=classification_credentials
|
16 |
-
)
|
17 |
|
18 |
def abnormal_stream(image):
|
19 |
try:
|
@@ -21,15 +8,18 @@ def abnormal_stream(image):
|
|
21 |
image.save(byte_io, 'png')
|
22 |
byte_io.seek(0)
|
23 |
|
24 |
-
r =
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
)
|
29 |
|
30 |
-
if
|
31 |
return {'확인불가': 1.0, r.status_code: 0.0, r.text: 0.0}, None
|
32 |
-
|
33 |
output_dict = {}
|
34 |
|
35 |
for item in r.json()['predictions']:
|
@@ -53,7 +43,7 @@ with gr.Blocks(
|
|
53 |
with gr.Column():
|
54 |
input_img = gr.Image(sources=["webcam"], type="pil")
|
55 |
with gr.Column():
|
56 |
-
output_label = gr.
|
57 |
output_audio = gr.Audio(autoplay=True)
|
58 |
dep = input_img.stream(abnormal_stream, [input_img], [output_label, output_audio])
|
59 |
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def abnormal_stream(image):
|
6 |
try:
|
|
|
8 |
image.save(byte_io, 'png')
|
9 |
byte_io.seek(0)
|
10 |
|
11 |
+
r = requests.post(
|
12 |
+
'https://6a051cv20250210-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/29f565b7-4710-47a5-8a47-723048ff7ec9/classify/iterations/Iteration2/image',
|
13 |
+
headers={
|
14 |
+
'Prediction-Key': '8uyKSiqRNbG2JLdMjI8AeOzADtORP3jRh5klqQr0JsJrBBt7x7iPJQQJ99BBACYeBjFXJ3w3AAAIACOGHg4K',
|
15 |
+
'Content-Type': 'application/octet-stream',
|
16 |
+
},
|
17 |
+
data=byte_io,
|
18 |
)
|
19 |
|
20 |
+
if r.status_code != 200:
|
21 |
return {'확인불가': 1.0, r.status_code: 0.0, r.text: 0.0}, None
|
22 |
+
|
23 |
output_dict = {}
|
24 |
|
25 |
for item in r.json()['predictions']:
|
|
|
43 |
with gr.Column():
|
44 |
input_img = gr.Image(sources=["webcam"], type="pil")
|
45 |
with gr.Column():
|
46 |
+
output_label = gr.Label()
|
47 |
output_audio = gr.Audio(autoplay=True)
|
48 |
dep = input_img.stream(abnormal_stream, [input_img], [output_label, output_audio])
|
49 |
|
requirements.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
azure-cognitiveservices-vision-customvision
|
|
|
|