hyunjunian commited on
Commit
e8486fd
·
1 Parent(s): ba6cc09

use numpy

Browse files
Files changed (1) hide show
  1. app.py +13 -11
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,16 @@ import requests
35
 
36
  def abnormal_stream(image):
37
  try:
38
- with open(image, 'rb') as f:
39
- r = requests.post(
40
- 'https://6a051cv20250210-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/29f565b7-4710-47a5-8a47-723048ff7ec9/classify/iterations/Iteration2/image',
41
- headers={
42
- 'Prediction-Key': '8uyKSiqRNbG2JLdMjI8AeOzADtORP3jRh5klqQr0JsJrBBt7x7iPJQQJ99BBACYeBjFXJ3w3AAAIACOGHg4K',
43
- 'Content-Type': 'application/octet-stream',
44
- },
45
- data=f.read(),
46
- )
 
47
 
48
  if r.status_code != 200:
49
  return {'확인불가': 1.0, r.status_code: 0.0, r.text: 0.0}
@@ -63,7 +65,7 @@ def abnormal_stream(image):
63
  with gr.Blocks() as demo:
64
  with gr.Row():
65
  with gr.Column():
66
- input_img = gr.Image(sources=["webcam"], type="filepath")
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 io, requests
3
+ import matplotlib.pyplot as plt
4
 
5
  # def abnormal(image):
6
  # if (image is None) or (image == ''):
 
36
 
37
  def abnormal_stream(image):
38
  try:
39
+ buf = io.BytesIO()
40
+ plt.imsave(buf, image, format='png')
41
+ r = requests.post(
42
+ 'https://6a051cv20250210-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/29f565b7-4710-47a5-8a47-723048ff7ec9/classify/iterations/Iteration2/image',
43
+ headers={
44
+ 'Prediction-Key': '8uyKSiqRNbG2JLdMjI8AeOzADtORP3jRh5klqQr0JsJrBBt7x7iPJQQJ99BBACYeBjFXJ3w3AAAIACOGHg4K',
45
+ 'Content-Type': 'application/octet-stream',
46
+ },
47
+ data=buf.getvalue(),
48
+ )
49
 
50
  if r.status_code != 200:
51
  return {'확인불가': 1.0, r.status_code: 0.0, r.text: 0.0}
 
65
  with gr.Blocks() as demo:
66
  with gr.Row():
67
  with gr.Column():
68
+ input_img = gr.Image(sources=["webcam"])
69
  with gr.Column():
70
  output_label = gr.Label()
71
  dep = input_img.stream(abnormal_stream, [input_img], [output_label])