PrismeFoot commited on
Commit
4dbcdb0
·
verified ·
1 Parent(s): 3c7dff6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -45
app.py CHANGED
@@ -1,91 +1,100 @@
1
  import os, uuid, subprocess, requests, feedparser, urllib.parse, re
2
  import streamlit as st
3
  from gtts import gTTS
 
4
 
5
- # --- 1. MOTEUR DE RECHERCHE D'ACTU (AUTO) ---
6
- def pipeline_actu(joueur):
7
  try:
8
  query = urllib.parse.quote(f"{joueur} football")
9
  url = f"https://google.com{query}&hl=fr&gl=FR&ceid=FR:fr"
10
  flux = feedparser.parse(url)
11
  if flux.entries:
12
  titre = flux.entries[0].title.split(" - ")[0]
13
- return f"ACTUALITÉ : {titre}. Une information qui secoue le monde du football en ce moment !"
14
- return f"INFO : {joueur} continue d'impressionner avec une performance de classe mondiale."
15
  except:
16
- return f"ALERTE : {joueur} est au centre de toutes les attentions ce week-end."
 
17
 
18
- # --- 2. MOTEUR D'IMAGE (AUTO) ---
19
- def pipeline_image(joueur):
20
  try:
21
- query = urllib.parse.quote(f"{joueur} football player portrait")
22
- url = f"https://bing.com{query}&qft=+filterui:aspect-tall+filterui:imagesize-large"
23
  headers = {"User-Agent": "Mozilla/5.0"}
24
  r = requests.get(url, headers=headers, timeout=10)
 
25
  links = re.findall(r'murl":"(http.*?)"', r.text)
26
  if links:
27
  path = f"img_{uuid.uuid4().hex[:4]}.jpg"
 
28
  with open(path, 'wb') as f:
29
- f.write(requests.get(links[0], timeout=10).content)
30
  return path
31
  except:
32
- return None
 
33
 
34
- # --- 3. MOTEUR VIDÉO (AUTO) ---
35
- def generer_video_finale(joueur, news):
36
  uid = uuid.uuid4().hex[:6]
37
  audio, video = f"audio_{uid}.mp3", f"PRISME_{uid}.mp4"
38
- img = pipeline_image(joueur)
39
 
40
- # Formatage texte
41
- mots = news.split()
42
- news_formatee = ""
43
  for i, mot in enumerate(mots):
44
- news_formatee += mot + ("\\n" if (i+1) % 4 == 0 else " ")
45
 
46
  try:
47
- gTTS(text=news, lang='fr').save(audio)
48
- source = ["-loop", "1", "-i", img] if img else ["-f", "lavfi", "-i", "color=c=0x0a0a0a:s=720x1280"]
49
-
50
- # Filtre Pro : Flou sur image + texte centré
51
- vf_base = "scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,boxblur=5:1" if img else "null"
 
 
 
52
  vf = (
53
- f"{vf_base},drawbox=y=ih/2-150:color=black@0.6:width=iw:height=450:t=fill,"
 
54
  f"drawtext=text='PRISME FOOT':fontcolor=yellow:fontsize=45:x=(w-text_w)/2:y=150,"
55
  f"drawtext=text='{joueur.upper()}':fontcolor=white:fontsize=65:x=(w-text_w)/2:y=300:box=1:boxcolor=red@0.8,"
56
- f"drawtext=text='{news_formatee}':fontcolor=white:fontsize=35:x=(w-text_w)/2:y=(h-text_h)/2+80"
57
  )
58
 
59
  cmd = ["ffmpeg", "-y"] + source + ["-i", audio, "-vf", vf, "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", video]
60
  subprocess.run(cmd, check=True)
61
 
62
- if img: os.remove(img)
63
- os.remove(audio)
 
 
64
  return video
65
- except:
 
66
  return None
67
 
68
- # --- INTERFACE ÉPURÉE (SANS BOUTONS MULTIPLES) ---
69
  st.set_page_config(page_title="Prisme Foot Studio", page_icon="⚽")
70
  st.title("⚽ Prisme Foot Studio - Automatique")
71
 
72
- nom_joueur = st.text_input("Entrez le nom du joueur", placeholder="Ex: Kylian Mbappé")
73
 
74
- # UN SEUL BOUTON POUR TOUT FAIRE
75
- if st.button("🚀 CRÉER LA VIDÉO MAINTENANT"):
76
- if nom_joueur:
77
- with st.spinner(f"Analyse, recherche et montage pour {nom_joueur} en cours..."):
78
- # Étape 1 : Récupérer l'actu
79
- actu = pipeline_actu(nom_joueur)
80
- # Étape 2 : Créer la vidéo
81
- video_path = generer_video_finale(nom_joueur, actu)
82
 
83
- if video_path:
84
- st.success(f"Vidéo générée pour {nom_joueur} !")
85
- st.video(video_path)
86
- with open(video_path, "rb") as f:
87
- st.download_button("📥 Télécharger la vidéo", f, file_name=f"{nom_joueur}_actu.mp4")
88
  else:
89
- st.error("Désolé, le montage a échoué. Réessayez.")
90
  else:
91
- st.warning("Veuillez saisir un nom de joueur.")
 
1
  import os, uuid, subprocess, requests, feedparser, urllib.parse, re
2
  import streamlit as st
3
  from gtts import gTTS
4
+ from bs4 import BeautifulSoup
5
 
6
+ # --- FONCTION 1 : RÉCUPÉRER L'ACTUALITÉ RÉELLE ---
7
+ def chercher_actu(joueur):
8
  try:
9
  query = urllib.parse.quote(f"{joueur} football")
10
  url = f"https://google.com{query}&hl=fr&gl=FR&ceid=FR:fr"
11
  flux = feedparser.parse(url)
12
  if flux.entries:
13
  titre = flux.entries[0].title.split(" - ")[0]
14
+ return f"INFO : {titre}. Une performance qui fait vibrer le monde du football aujourd'hui."
 
15
  except:
16
+ pass
17
+ return f"ACTUALITÉ : {joueur} continue d'impressionner sur le terrain cette saison."
18
 
19
+ # --- FONCTION 2 : RÉCUPÉRER L'IMAGE DE FOOT ---
20
+ def chercher_image(joueur):
21
  try:
22
+ query = urllib.parse.quote(f"{joueur} football portrait")
23
+ url = f"https://bing.com{query}&qft=+filterui:imagesize-large"
24
  headers = {"User-Agent": "Mozilla/5.0"}
25
  r = requests.get(url, headers=headers, timeout=10)
26
+ # Extraction du lien image
27
  links = re.findall(r'murl":"(http.*?)"', r.text)
28
  if links:
29
  path = f"img_{uuid.uuid4().hex[:4]}.jpg"
30
+ img_data = requests.get(links[0], timeout=10).content
31
  with open(path, 'wb') as f:
32
+ f.write(img_data)
33
  return path
34
  except:
35
+ pass
36
+ return None
37
 
38
+ # --- FONCTION 3 : GÉNÉRER LA VIDÉO ---
39
+ def fabriquer_video(joueur, texte):
40
  uid = uuid.uuid4().hex[:6]
41
  audio, video = f"audio_{uid}.mp3", f"PRISME_{uid}.mp4"
42
+ img = chercher_image(joueur)
43
 
44
+ # Formatage du texte (Retour à la ligne tous les 5 mots)
45
+ mots = texte.split()
46
+ texte_formate = ""
47
  for i, mot in enumerate(mots):
48
+ texte_formate += mot + ("\\n" if (i+1) % 5 == 0 else " ")
49
 
50
  try:
51
+ # 1. Créer l'audio
52
+ tts = gTTS(text=texte, lang='fr')
53
+ tts.save(audio)
54
+
55
+ # 2. Définir la source (Image ou Fond Noir)
56
+ source = ["-loop", "1", "-i", img] if img else ["-f", "lavfi", "-i", "color=c=0x101010:s=720x1280"]
57
+
58
+ # 3. Filtre FFmpeg (Portrait + Texte centré)
59
  vf = (
60
+ "scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,"
61
+ "drawbox=y=ih/2-150:color=black@0.6:width=iw:height=400:t=fill,"
62
  f"drawtext=text='PRISME FOOT':fontcolor=yellow:fontsize=45:x=(w-text_w)/2:y=150,"
63
  f"drawtext=text='{joueur.upper()}':fontcolor=white:fontsize=65:x=(w-text_w)/2:y=300:box=1:boxcolor=red@0.8,"
64
+ f"drawtext=text='{texte_formate}':fontcolor=white:fontsize=32:x=(w-text_w)/2:y=(h-text_h)/2+80"
65
  )
66
 
67
  cmd = ["ffmpeg", "-y"] + source + ["-i", audio, "-vf", vf, "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", video]
68
  subprocess.run(cmd, check=True)
69
 
70
+ # Nettoyage
71
+ if img and os.path.exists(img): os.remove(img)
72
+ if os.path.exists(audio): os.remove(audio)
73
+
74
  return video
75
+ except Exception as e:
76
+ st.error(f"Erreur technique : {e}")
77
  return None
78
 
79
+ # --- INTERFACE UNIQUE ---
80
  st.set_page_config(page_title="Prisme Foot Studio", page_icon="⚽")
81
  st.title("⚽ Prisme Foot Studio - Automatique")
82
 
83
+ joueur_input = st.text_input("Nom du joueur", placeholder="Ex: Kylian Mbappé")
84
 
85
+ if st.button("🚀 CRÉER LA VIDÉO"):
86
+ if joueur_input:
87
+ with st.spinner("Pipeline en cours (News + Image + Vidéo)..."):
88
+ # Lancement automatique
89
+ actu = chercher_actu(joueur_input)
90
+ video_finale = fabriquer_video(joueur_input, actu)
 
 
91
 
92
+ if video_finale:
93
+ st.video(video_finale)
94
+ st.success("Vidéo prête !")
95
+ with open(video_finale, "rb") as f:
96
+ st.download_button("📥 Télécharger", f, file_name=f"actu_{joueur_input}.mp4")
97
  else:
98
+ st.error("Le montage a échoué. Vérifiez vos fichiers.")
99
  else:
100
+ st.warning("Veuillez entrer un nom.")