Spaces:
Build error
Build error
Commit
·
65809e2
1
Parent(s):
907ffb3
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
|
| 3 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 4 |
from IPython.display import display, Javascript
|
| 5 |
-
from google.colab.output import eval_js
|
| 6 |
from base64 import b64decode
|
| 7 |
from IPython.display import Image
|
| 8 |
import cv2
|
|
@@ -12,59 +11,36 @@ import time
|
|
| 12 |
from transformers import BarkModel, BarkProcessor
|
| 13 |
from IPython.display import Audio
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
div.remove();
|
| 46 |
-
return canvas.toDataURL('image/jpeg', quality);
|
| 47 |
-
}
|
| 48 |
-
''')
|
| 49 |
-
display(js)
|
| 50 |
-
data = eval_js('takePhoto({})'.format(quality))
|
| 51 |
-
binary = b64decode(data.split(',')[1])
|
| 52 |
-
with open(filename, 'wb') as f:
|
| 53 |
-
f.write(binary)
|
| 54 |
-
return filename
|
| 55 |
-
|
| 56 |
-
# Capturing snaps using given button and saving them
|
| 57 |
-
|
| 58 |
-
try:
|
| 59 |
-
filename = take_photo()
|
| 60 |
-
print('Saved to {}'.format(filename))
|
| 61 |
-
|
| 62 |
-
# Show the image which was just taken.
|
| 63 |
-
display(Image(filename))
|
| 64 |
-
except Exception as err:
|
| 65 |
-
# Errors will be thrown if the user does not have a webcam or if they do not
|
| 66 |
-
# grant the page permission to access it.
|
| 67 |
-
print(str(err))
|
| 68 |
|
| 69 |
# Using the pre-trained Dog Breed Identification Model
|
| 70 |
|
|
@@ -73,9 +49,9 @@ dog_breed_model = AutoModelForImageClassification.from_pretrained("wesleyacheng/
|
|
| 73 |
|
| 74 |
# Importing the saved image
|
| 75 |
|
| 76 |
-
img_path='/content/n02088094_60.jpg'
|
| 77 |
|
| 78 |
-
image=cv2.imread(img_path)
|
| 79 |
|
| 80 |
# Preprocessing the captured image using pre-trained model based preprocessor
|
| 81 |
|
|
|
|
| 2 |
|
| 3 |
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 4 |
from IPython.display import display, Javascript
|
|
|
|
| 5 |
from base64 import b64decode
|
| 6 |
from IPython.display import Image
|
| 7 |
import cv2
|
|
|
|
| 11 |
from transformers import BarkModel, BarkProcessor
|
| 12 |
from IPython.display import Audio
|
| 13 |
|
| 14 |
+
|
| 15 |
+
# Using captured images
|
| 16 |
+
|
| 17 |
+
def process_webcam_images():
|
| 18 |
+
cap = cv2.VideoCapture(0) # 0 corresponds to the default camera (usually your webcam)
|
| 19 |
+
|
| 20 |
+
while True:
|
| 21 |
+
ret, frame = cap.read()
|
| 22 |
+
|
| 23 |
+
# Send the image to the Hugging Face model for classification
|
| 24 |
+
result = model(frame)
|
| 25 |
+
|
| 26 |
+
# Display the classification result
|
| 27 |
+
print(result)
|
| 28 |
+
|
| 29 |
+
# Display the captured image
|
| 30 |
+
cv2.imshow('Webcam Image', frame)
|
| 31 |
+
|
| 32 |
+
# Press 'q' to quit the loop
|
| 33 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
| 34 |
+
break
|
| 35 |
+
|
| 36 |
+
cap.release()
|
| 37 |
+
cv2.destroyAllWindows()
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
process_webcam_images()
|
| 41 |
+
|
| 42 |
+
image=process_webcam_images()
|
| 43 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Using the pre-trained Dog Breed Identification Model
|
| 46 |
|
|
|
|
| 49 |
|
| 50 |
# Importing the saved image
|
| 51 |
|
| 52 |
+
#img_path='/content/n02088094_60.jpg'
|
| 53 |
|
| 54 |
+
#image=cv2.imread(img_path)
|
| 55 |
|
| 56 |
# Preprocessing the captured image using pre-trained model based preprocessor
|
| 57 |
|