Ammar-Abdelhady-ai commited on
Commit
b244901
1 Parent(s): fa09cc6
Files changed (1) hide show
  1. main.py +9 -27
main.py CHANGED
@@ -10,25 +10,6 @@ from transformers import pipeline
10
 
11
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
12
  print("\n\n definition 2")
13
- def fit_threads(text):
14
- define.join()
15
-
16
- ######## Handel Sumarization model
17
-
18
- a = threading.Thread(target=summarization, args=(text[0],))
19
- b = threading.Thread(target=summarization, args=(text[1],))
20
- c = threading.Thread(target=summarization, args=(text[-1],))
21
-
22
- # Start all threads
23
- a.start()
24
- b.start()
25
- c.start()
26
-
27
- # Wait for all threads to finish
28
- a.join()
29
- b.join()
30
- c.join()
31
- print("Summarization Done")
32
 
33
 
34
 
@@ -47,10 +28,7 @@ df_vect = vectorizer.transform(x)
47
  ######### using summarizer model
48
  summ_data = []
49
 
50
- def summarization(text):
51
- global summ_data
52
- part = summarizer(text, max_length=150, min_length=30, do_sample=False)
53
- summ_data.append(part[0]["summary_text"].replace("\xa0", ""))
54
 
55
  print("start api code")
56
  app = FastAPI(project_name="cv")
@@ -61,6 +39,7 @@ async def read_root():
61
 
62
  @app.post("/prediction")
63
  async def detect(cv: UploadFile, number_of_jobs: int):
 
64
 
65
  if (type(number_of_jobs) != int) or (number_of_jobs < 1) or (number_of_jobs > df.shape[0]):
66
  raise HTTPException(
@@ -72,13 +51,16 @@ async def detect(cv: UploadFile, number_of_jobs: int):
72
  status_code=415, detail="Please inter PDF file "
73
  )
74
 
75
-
76
-
 
77
  cv_data = extract_text_from_pdf(await cv.read())
78
  index = len(cv_data)//3
79
  text = [cv_data[:index], cv_data[index:2*index], cv_data[2*index:]]
80
- fit_threads(text)
81
-
 
 
82
  data = " .".join(summ_data)
83
  summ_data.clear()
84
  cv_vect = vectorizer.transform([data])
 
10
 
11
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
12
  print("\n\n definition 2")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
 
 
28
  ######### using summarizer model
29
  summ_data = []
30
 
31
+
 
 
 
32
 
33
  print("start api code")
34
  app = FastAPI(project_name="cv")
 
39
 
40
  @app.post("/prediction")
41
  async def detect(cv: UploadFile, number_of_jobs: int):
42
+ print("pf")
43
 
44
  if (type(number_of_jobs) != int) or (number_of_jobs < 1) or (number_of_jobs > df.shape[0]):
45
  raise HTTPException(
 
51
  status_code=415, detail="Please inter PDF file "
52
  )
53
 
54
+ print("pf2")
55
+
56
+ summ_data =[]
57
  cv_data = extract_text_from_pdf(await cv.read())
58
  index = len(cv_data)//3
59
  text = [cv_data[:index], cv_data[index:2*index], cv_data[2*index:]]
60
+ for i in text:
61
+ part = summarizer(i, max_length=150, min_length=30, do_sample=False)
62
+ summ_data.append(part[0]["summary_text"].replace("\xa0", ""))
63
+ print("pf3")
64
  data = " .".join(summ_data)
65
  summ_data.clear()
66
  cv_vect = vectorizer.transform([data])