Downloads · 30 days
0
Bhagya123456789/women_safety
women_safety is a machine learning model from Bhagya123456789. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
pip install flask twilio sendgrid from flask import Flask, request, jsonify from twilio.rest import Client from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail
Downloads · 30 days
0
Access
Public
Updated Nov 23, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md2 KB · 57%
From the Hugging Face model README
pip install flask twilio sendgrid from flask import Flask, request, jsonify from twilio.rest import Client from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail
app = Flask(name)
TWILIO_SID = 'your_twilio_account_sid' TWILIO_AUTH_TOKEN = 'your_twilio_auth_token' TWILIO_PHONE_NUMBER = 'your_twilio_phone_number'
SENDGRID_API_KEY = 'your_sendgrid_api_key'
@app.route('/send-alert', methods=['POST']) def send_alert(): try: data = request.get_json() contacts = data.get('contacts', []) message_text = data.get('message', 'Emergency Alert!') location = data.get('location', 'Unknown location')
# Send SMS using Twilio
client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)
for contact in contacts:
if 'phone' in contact:
client.messages.create(
body=f"{message_text}\nLocation: {location}",
from_=TWILIO_PHONE_NUMBER,
to=contact['phone']
)
# Send emails using SendGrid
sg = SendGridAPIClient(SENDGRID_API_KEY)
for contact in contacts:
if 'email' in contact:
email = Mail(
from_email='[email protected]',
to_emails=contact['email'],
subject='Emergency Alert',
plain_text_content=f"{message_text}\nLocation: {location}"
)
sg.send(email)
return jsonify({"message": "Emergency alerts sent successfully!"}), 200
except Exception as e:
print(f"Error: {e}")
return jsonify({"error": "Failed to send alerts"}), 500
@app.route('/', methods=['GET']) def home(): return jsonify({"message": "Server is running"}), 200
if name == 'main': app.run(debug=True, port=5000)