mannnon commited on
Commit
7a2b369
·
verified ·
1 Parent(s): bbf2f13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -4
app.py CHANGED
@@ -6,6 +6,8 @@ import streamlit as st
6
  import matplotlib.pyplot as plt
7
  import pdfplumber
8
 
 
 
9
  from zebris_extractor import extract_zebris_csv
10
 
11
  st.set_page_config(page_title="Zebris — Profil biomécanique complet", layout="wide")
@@ -283,13 +285,36 @@ def extract_text_from_pdf(uploaded_pdf) -> str:
283
  raw = uploaded_pdf.read()
284
  uploaded_pdf.seek(0)
285
 
286
- text_parts = []
287
- with pdfplumber.open(io.BytesIO(raw)) as pdf:
288
- for page in pdf.pages:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  txt = page.extract_text() or ""
290
  if txt:
291
  text_parts.append(txt)
292
- return "\n".join(text_parts)
 
 
 
 
 
 
 
293
 
294
  def find_float_after_label(text: str, label: str, max_numbers: int = 2, window: int = 1200):
295
  """
@@ -438,6 +463,10 @@ def parse_zebris_pdf(uploaded_pdf):
438
 
439
  full_text = " ".join(page_texts)
440
  data["speed_kmh"] = extract_speed_from_text(full_text)
 
 
 
 
441
 
442
  # fallback si nom non récupéré via fichier
443
  if not data["athlete_name"]:
 
6
  import matplotlib.pyplot as plt
7
  import pdfplumber
8
 
9
+ from PyPDF2 import PdfReader
10
+
11
  from zebris_extractor import extract_zebris_csv
12
 
13
  st.set_page_config(page_title="Zebris — Profil biomécanique complet", layout="wide")
 
285
  raw = uploaded_pdf.read()
286
  uploaded_pdf.seek(0)
287
 
288
+ # 1) Essai avec pdfplumber
289
+ try:
290
+ text_parts = []
291
+ with pdfplumber.open(io.BytesIO(raw)) as pdf:
292
+ for page in pdf.pages:
293
+ txt = page.extract_text() or ""
294
+ if txt:
295
+ text_parts.append(txt)
296
+ text = "\n".join(text_parts).strip()
297
+ if text:
298
+ return text
299
+ except Exception:
300
+ pass
301
+
302
+ # 2) Fallback avec PyPDF2
303
+ try:
304
+ reader = PdfReader(io.BytesIO(raw))
305
+ text_parts = []
306
+ for page in reader.pages:
307
  txt = page.extract_text() or ""
308
  if txt:
309
  text_parts.append(txt)
310
+ text = "\n".join(text_parts).strip()
311
+ if text:
312
+ return text
313
+ except Exception:
314
+ pass
315
+
316
+ # 3) Si rien ne marche
317
+ return ""
318
 
319
  def find_float_after_label(text: str, label: str, max_numbers: int = 2, window: int = 1200):
320
  """
 
463
 
464
  full_text = " ".join(page_texts)
465
  data["speed_kmh"] = extract_speed_from_text(full_text)
466
+ if not full_text.strip():
467
+ data["attaque_pdf"] = "indéterminée"
468
+ return data
469
+
470
 
471
  # fallback si nom non récupéré via fichier
472
  if not data["athlete_name"]: