Spaces:
Sleeping
Sleeping
fix: generate random md5 hash if None on image
Browse files- src/input_handling.py +9 -1
src/input_handling.py
CHANGED
@@ -25,6 +25,14 @@ both the UI elements (setup_input_UI) and the validation functions.
|
|
25 |
#allowed_image_types = ['webp']
|
26 |
allowed_image_types = ['jpg', 'jpeg', 'png', 'webp']
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# autogenerated class to hold the input data
|
30 |
class InputObservation:
|
@@ -101,7 +109,7 @@ class InputObservation:
|
|
101 |
return {
|
102 |
#"image": self.image,
|
103 |
"image_filename": self.uploaded_filename.name if self.uploaded_filename else None,
|
104 |
-
"image_md5": hashlib.md5(self.uploaded_filename.read()).hexdigest() if self.uploaded_filename else
|
105 |
"latitude": self.latitude,
|
106 |
"longitude": self.longitude,
|
107 |
"author_email": self.author_email,
|
|
|
25 |
#allowed_image_types = ['webp']
|
26 |
allowed_image_types = ['jpg', 'jpeg', 'png', 'webp']
|
27 |
|
28 |
+
import random
|
29 |
+
import string
|
30 |
+
def generate_random_md5():
|
31 |
+
# Generate a random string
|
32 |
+
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=16))
|
33 |
+
# Encode the string and compute its MD5 hash
|
34 |
+
md5_hash = hashlib.md5(random_string.encode()).hexdigest()
|
35 |
+
return md5_hash
|
36 |
|
37 |
# autogenerated class to hold the input data
|
38 |
class InputObservation:
|
|
|
109 |
return {
|
110 |
#"image": self.image,
|
111 |
"image_filename": self.uploaded_filename.name if self.uploaded_filename else None,
|
112 |
+
"image_md5": hashlib.md5(self.uploaded_filename.read()).hexdigest() if self.uploaded_filename else generate_random_md5(),
|
113 |
"latitude": self.latitude,
|
114 |
"longitude": self.longitude,
|
115 |
"author_email": self.author_email,
|