youssef1214 commited on
Commit
f25d682
1 Parent(s): a8ce4bd

adding lithen to Compliants and summary

Browse files
Files changed (1) hide show
  1. main.py +32 -1
main.py CHANGED
@@ -39,11 +39,14 @@ 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")
45
  firebase_admin.initialize_app(cred)
46
-
47
  # Model summury
48
  model_name="abdalrahmanshahrour/auto-arabic-summarization"
49
  preprocessor = ArabertPreprocessor(model_name="")
@@ -209,7 +212,35 @@ def genereteotp (email):
209
  s.sendmail(msg['From'], msg['To'], msg.as_string())
210
  # terminate the SMTP session
211
  s.quit()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
 
 
213
  # Main Server inilization
214
  app = FastAPI()
215
 
 
39
  import os
40
  import math
41
  import random
42
+ import threading
43
+ import Classes
44
+
45
  # Firebase ininlaziton
46
  cred = credentials.Certificate(
47
  "text-to-emotions-firebase-adminsdk-8isbn-dffbdf01e8.json")
48
  firebase_admin.initialize_app(cred)
49
+ db = firestore.client()
50
  # Model summury
51
  model_name="abdalrahmanshahrour/auto-arabic-summarization"
52
  preprocessor = ArabertPreprocessor(model_name="")
 
212
  s.sendmail(msg['From'], msg['To'], msg.as_string())
213
  # terminate the SMTP session
214
  s.quit()
215
+ #Threading functions
216
+ queuedUnSummurizedShawkas = []
217
+ semphoreShakwas=threading.Semaphore(0)
218
+ def summrizedshakwas():
219
+ global queuedUnSummurizedShawkas
220
+ global semphoreShakwas
221
+ semphoreShakwas.acquire()
222
+ shawka=queuedUnSummurizedShawkas.pop(0)
223
+ tmpdict= modelsummary(shawka.complaintbody)
224
+ shawka.summary=tmpdict['summary']
225
+ shawka.set_data()
226
+ thread = threading.Thread(target=target_function, args=(input,))
227
+ thread.start()
228
+
229
+ #lithening to changes of documnts
230
+ callback_done = threading.Event()
231
+ def on_snapshot(doc_snapshot, changes, read_time):
232
+ for doc in doc_snapshot:
233
+ global queuedUnSummurizedShawkas
234
+ global semphoreShakwas
235
+ # print(doc.to_dict())
236
+ shakw = Classes.Shakwa.from_dict(source=doc.to_dict())
237
+ shakw.complaintbody
238
+ if shakw.summary==None:
239
+ queuedUnSummurizedShawkas.append(shakw)
240
+ semphoreShakwas.release()
241
+ callback_done.set()
242
 
243
+ docwatch= db.collection("complaints").on_snapshot(on_snapshot,)
244
  # Main Server inilization
245
  app = FastAPI()
246