Spaces:
Runtime error
Runtime error
youssef1214
commited on
Commit
•
6ade7cf
1
Parent(s):
d87c0e6
adding otp to server
Browse files
main.py
CHANGED
@@ -34,6 +34,11 @@ from transformers import BertTokenizer, AutoModelForSeq2SeqLM, pipeline
|
|
34 |
from arabert.preprocess import ArabertPreprocessor
|
35 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
36 |
import re
|
|
|
|
|
|
|
|
|
|
|
37 |
# Firebase ininlaziton
|
38 |
cred = credentials.Certificate(
|
39 |
"text-to-emotions-firebase-adminsdk-8isbn-dffbdf01e8.json")
|
@@ -50,6 +55,8 @@ pipeline1 = pipeline("text2text-generation",model=modelsummary,tokenizer=tokeniz
|
|
50 |
# Model inilization
|
51 |
isristemmer = ISRIStemmer()
|
52 |
model = from_pretrained_keras('MahmoudNasser/GRU-MODEL-EMOTION-AR-TEXT-76jP')
|
|
|
|
|
53 |
|
54 |
|
55 |
def stemming(txt):
|
@@ -170,7 +177,34 @@ def modelpredict(data):
|
|
170 |
return {'anger': float(pred[0][0]), 'sadness': float(pred[0][1]), 'joy': float(pred[0][2]), 'surprise': float(pred[0][3]),
|
171 |
'love': float(pred[0][4]), 'sympathy': float(pred[0][5]), 'fear': float(pred[0][6])}
|
172 |
# return {"anger": .90, "happy": .02, "emotionlabel": "anger"}
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
# Main Server inilization
|
176 |
app = FastAPI()
|
@@ -185,6 +219,24 @@ async def read_root(request:Request):
|
|
185 |
return modelsummary(json_data['text'])
|
186 |
else:
|
187 |
raise HTTPException(status_code=400, detail="Missing text value")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
@app.post("/predict")
|
189 |
async def read_root(request: Request):
|
190 |
json_data = await request.json()
|
|
|
34 |
from arabert.preprocess import ArabertPreprocessor
|
35 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
36 |
import re
|
37 |
+
import smtplib
|
38 |
+
from email.mime.text import MIMEText
|
39 |
+
import os
|
40 |
+
import math
|
41 |
+
import random
|
42 |
# Firebase ininlaziton
|
43 |
cred = credentials.Certificate(
|
44 |
"text-to-emotions-firebase-adminsdk-8isbn-dffbdf01e8.json")
|
|
|
55 |
# Model inilization
|
56 |
isristemmer = ISRIStemmer()
|
57 |
model = from_pretrained_keras('MahmoudNasser/GRU-MODEL-EMOTION-AR-TEXT-76jP')
|
58 |
+
# dictinarties for email OTP
|
59 |
+
emailOTP={}
|
60 |
|
61 |
|
62 |
def stemming(txt):
|
|
|
177 |
return {'anger': float(pred[0][0]), 'sadness': float(pred[0][1]), 'joy': float(pred[0][2]), 'surprise': float(pred[0][3]),
|
178 |
'love': float(pred[0][4]), 'sympathy': float(pred[0][5]), 'fear': float(pred[0][6])}
|
179 |
# return {"anger": .90, "happy": .02, "emotionlabel": "anger"}
|
180 |
+
|
181 |
+
#OTP code
|
182 |
+
def genereteotp (email):
|
183 |
+
digits = "0123456789"
|
184 |
+
OTP = ""
|
185 |
+
for i in range(6):
|
186 |
+
OTP += digits[math.floor(random.random()*10)]
|
187 |
+
emailverification[email]=OTP
|
188 |
+
otp = "your otp is "+OTP
|
189 |
+
s = smtplib.SMTP('smtp.gmail.com', 587)
|
190 |
+
# start TLS for security
|
191 |
+
s.starttls()
|
192 |
+
# Authentication
|
193 |
+
s.login("youssefmk1214@gmail.com", "lipnacjbsxmjpjxm")
|
194 |
+
# message to be sent
|
195 |
+
message = otp
|
196 |
+
# instance of MIMEText
|
197 |
+
msg = MIMEText(message)
|
198 |
+
# sender's email address
|
199 |
+
msg['From'] = "youssefmk1214@gmail.com"
|
200 |
+
# recipient's email address
|
201 |
+
msg['To'] = email
|
202 |
+
# subject of the email
|
203 |
+
msg['Subject'] = " Shakwa Textual OTP"
|
204 |
+
# send the message via SMTP server
|
205 |
+
s.sendmail(msg['From'], msg['To'], msg.as_string())
|
206 |
+
# terminate the SMTP session
|
207 |
+
s.quit()
|
208 |
|
209 |
# Main Server inilization
|
210 |
app = FastAPI()
|
|
|
219 |
return modelsummary(json_data['text'])
|
220 |
else:
|
221 |
raise HTTPException(status_code=400, detail="Missing text value")
|
222 |
+
@app.post("/getOTPCode")
|
223 |
+
async def read_root(request:Request):
|
224 |
+
json_data = await request.json()
|
225 |
+
if 'email' in json_data:
|
226 |
+
genereteotp(json_data["email"])
|
227 |
+
return "message was sent succesufully to "+json_data['email']
|
228 |
+
else:
|
229 |
+
raise HTTPException(status_code=400, detail="Missing email value")
|
230 |
+
@app.post("/verifyOTP")
|
231 |
+
async def read_root(request:Request):
|
232 |
+
if 'email' in json_data and 'otpcode' in json_data:
|
233 |
+
if json_data['otpcode'] ==emailOTP[json_data['email']] :
|
234 |
+
return "OTP verified succesufully "
|
235 |
+
else:
|
236 |
+
return "OTP Code is wrong "
|
237 |
+
else:
|
238 |
+
raise HTTPException(status_code=400, detail="Missing email value")
|
239 |
+
|
240 |
@app.post("/predict")
|
241 |
async def read_root(request: Request):
|
242 |
json_data = await request.json()
|