Update app.py
Browse files
app.py
CHANGED
@@ -77,9 +77,14 @@ def save_image_to_hugging_face(image, name, roll_no):
|
|
77 |
""" Saves the image locally to the KNOWN_FACES_DIR and uploads it to Hugging Face. """
|
78 |
filename = f"{name}_{roll_no}.jpg"
|
79 |
local_path = os.path.join(KNOWN_FACES_DIR, filename) # Ensure it's saved in the known_faces directory
|
80 |
-
image.save(local_path)
|
81 |
|
82 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
api.upload_file(path_or_fileobj=local_path, path_in_repo=filename, repo_id=REPO_ID, repo_type="space", token=hf_token)
|
84 |
st.success(f"Image uploaded to Hugging Face: {filename}")
|
85 |
except Exception as e:
|
|
|
77 |
""" Saves the image locally to the KNOWN_FACES_DIR and uploads it to Hugging Face. """
|
78 |
filename = f"{name}_{roll_no}.jpg"
|
79 |
local_path = os.path.join(KNOWN_FACES_DIR, filename) # Ensure it's saved in the known_faces directory
|
|
|
80 |
|
81 |
try:
|
82 |
+
# Convert image to RGB if not already in RGB mode (PIL handling)
|
83 |
+
if image.mode != "RGB":
|
84 |
+
image = image.convert("RGB")
|
85 |
+
image.save(local_path) # Save image locally to known_faces directory
|
86 |
+
|
87 |
+
# Upload the file to Hugging Face
|
88 |
api.upload_file(path_or_fileobj=local_path, path_in_repo=filename, repo_id=REPO_ID, repo_type="space", token=hf_token)
|
89 |
st.success(f"Image uploaded to Hugging Face: {filename}")
|
90 |
except Exception as e:
|