Commit
·
990c881
1
Parent(s):
13642a2
Upload app.py
Browse files
app.py
CHANGED
|
@@ -4,13 +4,13 @@ import cv2
|
|
| 4 |
|
| 5 |
learn = load_learner('resnet18_model.pkl')
|
| 6 |
|
| 7 |
-
categories = ('Black','White')
|
| 8 |
-
|
| 9 |
|
| 10 |
|
| 11 |
def classify_image(image):
|
| 12 |
-
is_people,_,probs = learn.predict(PILImage.create(image))
|
| 13 |
-
return dict(zip(categories,map(float,probs)))
|
|
|
|
| 14 |
|
| 15 |
def capture_image(cam):
|
| 16 |
cam = cv2.VideoCapture(0)
|
|
@@ -27,17 +27,14 @@ def webcam():
|
|
| 27 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 28 |
yield frame
|
| 29 |
|
|
|
|
| 30 |
image = gr.inputs.Image(shape=(192, 192), label="Upload Image", source="upload")
|
| 31 |
webcam = gr.inputs.Image(shape=(192, 192), label="Webcam Image", source="webcam")
|
| 32 |
label = gr.outputs.Label()
|
| 33 |
|
| 34 |
-
examples=['example1.jpg','example2.jpg','example3.jpg']
|
| 35 |
|
| 36 |
intf = gr.Interface(fn=classify_image, inputs=[image, webcam], outputs=label, examples=examples,
|
| 37 |
-
allow_flagging=
|
| 38 |
-
|
| 39 |
-
intf.launch(inline=False)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
|
|
|
|
|
| 4 |
|
| 5 |
learn = load_learner('resnet18_model.pkl')
|
| 6 |
|
| 7 |
+
categories = ('Black', 'White')
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def classify_image(image):
|
| 11 |
+
is_people, _, probs = learn.predict(PILImage.create(image))
|
| 12 |
+
return dict(zip(categories, map(float, probs)))
|
| 13 |
+
|
| 14 |
|
| 15 |
def capture_image(cam):
|
| 16 |
cam = cv2.VideoCapture(0)
|
|
|
|
| 27 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 28 |
yield frame
|
| 29 |
|
| 30 |
+
|
| 31 |
image = gr.inputs.Image(shape=(192, 192), label="Upload Image", source="upload")
|
| 32 |
webcam = gr.inputs.Image(shape=(192, 192), label="Webcam Image", source="webcam")
|
| 33 |
label = gr.outputs.Label()
|
| 34 |
|
| 35 |
+
examples = [['example1.jpg'], ['example2.jpg'], ['example3.jpg']] # Nested list for multiple input components
|
| 36 |
|
| 37 |
intf = gr.Interface(fn=classify_image, inputs=[image, webcam], outputs=label, examples=examples,
|
| 38 |
+
allow_flagging='never') # Set allow_flagging parameter as a string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
intf.launch()
|