Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,38 +8,72 @@ import csv
|
|
8 |
from datetime import datetime
|
9 |
|
10 |
############################################
|
11 |
-
import matplotlib.pyplot as plt
|
12 |
-
import pylab # this allows you to control figure size
|
13 |
-
pylab.rcParams['figure.figsize'] = (10.0, 8.0) # this controls figure size in the notebook
|
14 |
-
|
15 |
-
import io
|
16 |
-
import streamlit as st
|
17 |
-
bytes_data=None
|
18 |
-
|
|
|
19 |
##################################################3
|
20 |
|
21 |
-
import gradio as gr
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
app = Flask(__name__)
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
#
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
# def attend():
|
45 |
# # Face recognition variables
|
|
|
8 |
from datetime import datetime
|
9 |
|
10 |
############################################
|
11 |
+
# import matplotlib.pyplot as plt
|
12 |
+
# import pylab # this allows you to control figure size
|
13 |
+
# pylab.rcParams['figure.figsize'] = (10.0, 8.0) # this controls figure size in the notebook
|
14 |
+
|
15 |
+
# import io
|
16 |
+
# import streamlit as st
|
17 |
+
# bytes_data=None
|
18 |
+
from flask_socketio import SocketIO,emit
|
19 |
+
import base64
|
20 |
##################################################3
|
21 |
|
22 |
+
# import gradio as gr
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
app = Flask(__name__)
|
28 |
+
app.config['SECRET_KEY'] = 'secret!'
|
29 |
+
socket = SocketIO(app,async_mode="eventlet")
|
30 |
+
|
31 |
+
def base64_to_image(base64_string):
|
32 |
+
# Extract the base64 encoded binary data from the input string
|
33 |
+
base64_data = base64_string.split(",")[1]
|
34 |
+
# Decode the base64 data to bytes
|
35 |
+
image_bytes = base64.b64decode(base64_data)
|
36 |
+
# Convert the bytes to numpy array
|
37 |
+
image_array = np.frombuffer(image_bytes, dtype=np.uint8)
|
38 |
+
# Decode the numpy array as an image using OpenCV
|
39 |
+
image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
|
40 |
+
return image
|
41 |
+
|
42 |
+
@socket.on("connect")
|
43 |
+
def test_connect():
|
44 |
+
print("Connected")
|
45 |
+
emit("my response", {"data": "Connected"})
|
46 |
+
|
47 |
+
@socket.on("image")
|
48 |
+
def receive_image(image):
|
49 |
+
# Decode the base64-encoded image data
|
50 |
+
image = base64_to_image(image)
|
51 |
+
image = cv2.resize(image, (224, 224), interpolation=cv2.INTER_AREA)
|
52 |
+
# emit("processed_image", image)
|
53 |
+
# Make the image a numpy array and reshape it to the models input shape.
|
54 |
+
image = np.asarray(image, dtype=np.float32).reshape(1, 224, 224, 3)
|
55 |
+
image = (image / 127.5) - 1
|
56 |
+
# Predicts the model
|
57 |
+
prediction = model.predict(image)
|
58 |
+
index = np.argmax(prediction)
|
59 |
+
class_name = class_names[index]
|
60 |
+
confidence_score = prediction[0][index]
|
61 |
+
emit("result",{"name":str(class_name),"score":str(confidence_score)})
|
62 |
+
# flag1 = True
|
63 |
+
|
64 |
+
# @app.route('/at')
|
65 |
+
# def testme():
|
66 |
+
# global flag1
|
67 |
+
# # return "i am in testme"
|
68 |
+
# while flag1 is True:
|
69 |
|
70 |
+
# img_file_buffer=st.camera_input("Take a picture")
|
71 |
+
# if img_file_buffer is not None:
|
72 |
+
# test_image = Image.open(img_file_buffer)
|
73 |
+
# st.image(test_image, use_column_width=True)
|
74 |
+
# if bytes_data is None:
|
75 |
+
# flag1 = False
|
76 |
+
# st.stop()
|
77 |
|
78 |
# def attend():
|
79 |
# # Face recognition variables
|