Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,27 @@ import torch
|
|
| 3 |
from PIL import Image
|
| 4 |
import requests
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# URL de l'image d'exemple
|
| 7 |
url = "https://www.saint-genes.com/wp-content/uploads/2019/10/DSC05405.jpg"
|
| 8 |
image = Image.open(requests.get(url, stream=True).raw)
|
|
@@ -31,3 +52,17 @@ for score, label, box in zip(results["scores"], results["labels"], results["boxe
|
|
| 31 |
persons += 1 # Incrémentation correcte
|
| 32 |
|
| 33 |
print(f"Total persons detected: {persons}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import requests
|
| 5 |
|
| 6 |
+
# Fonction pour envoyer l'email
|
| 7 |
+
def send_email(api_key, to_email, subject, content):
|
| 8 |
+
url = "https://api.sendgrid.com/v3/mail/send"
|
| 9 |
+
headers = {
|
| 10 |
+
"Authorization": f"Bearer {api_key}",
|
| 11 |
+
"Content-Type": "application/json"
|
| 12 |
+
}
|
| 13 |
+
data = {
|
| 14 |
+
"personalizations": [{
|
| 15 |
+
"to": [{"email": to_email}],
|
| 16 |
+
"subject": subject
|
| 17 |
+
}],
|
| 18 |
+
"from": {"email": "your-email@example.com"},
|
| 19 |
+
"content": [{
|
| 20 |
+
"type": "text/plain",
|
| 21 |
+
"value": content
|
| 22 |
+
}]
|
| 23 |
+
}
|
| 24 |
+
response = requests.post(url, headers=headers, json=data)
|
| 25 |
+
return response.status_code, response.text
|
| 26 |
+
|
| 27 |
# URL de l'image d'exemple
|
| 28 |
url = "https://www.saint-genes.com/wp-content/uploads/2019/10/DSC05405.jpg"
|
| 29 |
image = Image.open(requests.get(url, stream=True).raw)
|
|
|
|
| 52 |
persons += 1 # Incrémentation correcte
|
| 53 |
|
| 54 |
print(f"Total persons detected: {persons}")
|
| 55 |
+
|
| 56 |
+
# Définir les variables pour l'email
|
| 57 |
+
expected_number_of_persons = 30 # Nombre attendu de personnes
|
| 58 |
+
absents = expected_number_of_persons - persons
|
| 59 |
+
email_subject = "Notification d'absents"
|
| 60 |
+
email_content = f"Le nombre de personnes présentes est de {persons}. Le nombre d'absents est de {absents}."
|
| 61 |
+
|
| 62 |
+
# Clé API SendGrid et adresse email du destinataire
|
| 63 |
+
api_key = "YOUR_SENDGRID_API_KEY"
|
| 64 |
+
to_email = "recipient@example.com"
|
| 65 |
+
|
| 66 |
+
# Envoyer l'email
|
| 67 |
+
status_code, response_text = send_email(api_key, to_email, email_subject, email_content)
|
| 68 |
+
print(f"Email sent with status code {status_code}: {response_text}")
|