forked from OscarSantosMu/Chikoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
87 lines (67 loc) · 2.74 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from flask import Flask, render_template, request, jsonify, make_response
import cohere
from classifications import examples
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from mako.template import Template
from flask_cors import CORS, cross_origin
from functools import wraps
app = Flask(__name__)
co = cohere.Client('VI8IBNMDAZhU8FoqXh81eoM988zV4f8cjgw0EyBZ')
CORS(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/manage_message', methods=['POST'])
def manage_message():
data = request.get_json()
mensaje = data.get('message')
if mensaje:
co = cohere.Client("VI8IBNMDAZhU8FoqXh81eoM988zV4f8cjgw0EyBZ")
classifications = co.classify(
model='large',
inputs=[mensaje],
examples=examples)
prediction = classifications[0].prediction
return jsonify({'mensaje': prediction})
def add_cors_headers(func):
@wraps(func)
def decorated_function(*args, **kwargs):
response = make_response(func(*args, **kwargs))
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"
response.headers["Access-Control-Allow-Headers"] = "Content-Type"
return response
return decorated_function
@app.route('/register', methods=['POST','OPTIONS'])
@add_cors_headers
@cross_origin()
def register():
data = request.get_json()
email = data['email']
display_name = data.get('display_name', 'Usuario')
image_url = "https://www.tigrehacks.me/logo.png"
email_template = Template(filename='email_template.mako')
# Renderiza la plantilla con los datos del usuario
html_content = email_template.render(display_name=display_name, image_url=image_url)
# Configura el contenido del correo electrónico de bienvenida
message = MIMEMultipart()
message['Subject'] = 'Gracias por registrarte en Tigre Hacks 🐯'
message['From'] = '[email protected]'
message['To'] = email
message.attach(MIMEText(html_content, 'html'))
# Configura las credenciales de tu servicio de correo electrónico aquí
username = '[email protected]'
password = 'imkkiakbdsletupm'
# Envía el correo electrónico
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(username, password)
server.sendmail(username, email, message.as_string())
server.quit()
return jsonify({'message': 'Correo electrónico enviado correctamente'}), 200
except Exception as e:
print(f'Error al enviar el correo electrónico: {e}')
return jsonify({'message': 'Error al enviar el correo electrónico'}), 500