Flo161 commited on
Commit
e41304e
·
1 Parent(s): ca96738

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -39,26 +39,23 @@ def extract_paragraphs_by_vertical_spacing(pdf_data, spacing_threshold=10):
39
  previous_bottom = None
40
 
41
  for block in blocks:
42
- x0, y0, x1, y1 = block[:4] # Coordonnées du bloc de texte
43
- text = block[4] # Texte du bloc
44
 
45
- # Mesurez l'espacement vertical entre les blocs de texte
46
  if previous_bottom is not None:
47
  vertical_spacing = y0 - previous_bottom
48
  else:
49
  vertical_spacing = 0
50
 
51
- # Si l'espacement vertical dépasse le seuil, considérez-le comme un nouveau paragraphe
52
  if vertical_spacing > spacing_threshold:
53
  if current_paragraph:
54
  paragraphs.append(current_paragraph.strip())
55
  current_paragraph = text
56
  else:
57
- current_paragraph += " " + text # Ajoutez le texte au paragraphe actuel
58
 
59
  previous_bottom = y1
60
 
61
- # Ajoutez le dernier paragraphe de la page
62
  if current_paragraph:
63
  paragraphs.append(current_paragraph.strip())
64
 
@@ -83,14 +80,21 @@ if uploaded_file is not None:
83
 
84
  for paragraph in paragraphs:
85
  summary = summarizer(paragraph, max_length=(len(paragraph) / 2), min_length=10, do_sample=False)
86
- summary_text = add_line_breaks_to_summary(summary[0]['summary_text'], 40)
87
 
88
  # Create a slide
89
  slide = prs.slides.add_slide(prs.slide_layouts[5])
90
 
91
- # Add the paragraph to the slide
92
- left = top = Inches(1)
 
93
  width = height = Inches(5)
 
 
 
 
 
 
94
  txBox = slide.shapes.add_textbox(left, top, width, height)
95
  tf = txBox.text_frame
96
  p = tf.add_paragraph()
@@ -99,18 +103,6 @@ if uploaded_file is not None:
99
  p = tf.add_paragraph()
100
  p.text = summary_text
101
 
102
- # Generate and add the image to the slide
103
- image_bytes = query({
104
- "inputs": 'A picture without text about: ' + summary[0]['summary_text']
105
- })
106
- image = Image.open(io.BytesIO(image_bytes))
107
- temp_img_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
108
- image.save(temp_img_path)
109
-
110
- left = Inches(1)
111
- top = Inches(2)
112
- pic = slide.shapes.add_picture(temp_img_path, left, top, width, height)
113
-
114
  i += 1
115
 
116
  # Save the PowerPoint presentation
 
39
  previous_bottom = None
40
 
41
  for block in blocks:
42
+ x0, y0, x1, y1 = block[:4]
43
+ text = block[4]
44
 
 
45
  if previous_bottom is not None:
46
  vertical_spacing = y0 - previous_bottom
47
  else:
48
  vertical_spacing = 0
49
 
 
50
  if vertical_spacing > spacing_threshold:
51
  if current_paragraph:
52
  paragraphs.append(current_paragraph.strip())
53
  current_paragraph = text
54
  else:
55
+ current_paragraph += " " + text
56
 
57
  previous_bottom = y1
58
 
 
59
  if current_paragraph:
60
  paragraphs.append(current_paragraph.strip())
61
 
 
80
 
81
  for paragraph in paragraphs:
82
  summary = summarizer(paragraph, max_length=(len(paragraph) / 2), min_length=10, do_sample=False)
83
+ summary_text = add_line_breaks_to_summary(summary[0]['summary_text'], 70)
84
 
85
  # Create a slide
86
  slide = prs.slides.add_slide(prs.slide_layouts[5])
87
 
88
+ # Add the image to the slide at the bottom
89
+ left = Inches(1)
90
+ top = Inches(2)
91
  width = height = Inches(5)
92
+ pic = slide.shapes.add_picture(temp_img_path, left, top, width, height)
93
+
94
+ # Add the paragraph to the slide at the top
95
+ left = top = Inches(1)
96
+ width = Inches(5)
97
+ height = Inches(1.5)
98
  txBox = slide.shapes.add_textbox(left, top, width, height)
99
  tf = txBox.text_frame
100
  p = tf.add_paragraph()
 
103
  p = tf.add_paragraph()
104
  p.text = summary_text
105
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  i += 1
107
 
108
  # Save the PowerPoint presentation