PrismeFoot commited on
Commit
685721a
·
verified ·
1 Parent(s): 4dbcdb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -71
app.py CHANGED
@@ -1,100 +1,78 @@
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.")
 
1
+ import os, uuid, subprocess, feedparser, urllib.parse
2
  import streamlit as st
3
  from gtts import gTTS
 
4
 
5
+ # --- FONCTION DE RECHERCHE ---
6
+ def recuperer_news_reelle(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
+ # On prend le titre complet pour avoir une phrase riche
13
+ return flux.entries[0].title
14
+ return f"INFO : {joueur} continue de briller sur les terrains cette semaine."
15
  except:
16
+ return f"ACTUALITÉ : {joueur} est au centre des discussions sportives."
 
17
 
18
+ # --- MOTEUR VIDÉO ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def fabriquer_video(joueur, texte):
20
  uid = uuid.uuid4().hex[:6]
21
+ audio, video = f"a_{uid}.mp3", f"v_{uid}.mp4"
 
22
 
23
+ # Formatage du texte (retour à la ligne pour FFmpeg)
24
+ texte_clean = texte.replace("'", " ").replace('"', " ")
25
+ mots = texte_clean.split()
26
  texte_formate = ""
27
  for i, mot in enumerate(mots):
28
  texte_formate += mot + ("\\n" if (i+1) % 5 == 0 else " ")
29
 
30
  try:
31
+ # 1. Audio
32
+ gTTS(text=texte_clean, lang='fr').save(audio)
 
33
 
34
+ # 2. FFmpeg : Fond de couleur pro + Texte structuré
35
+ cmd =
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ subprocess.run(cmd, check=True)
 
38
  if os.path.exists(audio): os.remove(audio)
 
39
  return video
40
  except Exception as e:
41
+ st.error(f"Erreur rendu : {e}")
42
  return None
43
 
44
+ # --- INTERFACE (AVEC CHAMP DE TEXTE RÉACTIVÉ) ---
45
  st.set_page_config(page_title="Prisme Foot Studio", page_icon="⚽")
46
+ st.title("⚽ Prisme Foot Studio - Contrôle Total")
47
+
48
+ # Initialisation du texte dans la session
49
+ if 'script' not in st.session_state:
50
+ st.session_state['script'] = ""
51
+
52
+ nom = st.text_input("👤 Nom du joueur", placeholder="Ex: Kylian Mbappé")
53
+
54
+ # ÉTAPE 1 : Rechercher
55
+ if st.button("🔍 1. CHERCHER L'ACTUALITÉ"):
56
+ if nom:
57
+ with st.spinner("Recherche des news..."):
58
+ st.session_state['script'] = recuperer_news_reelle(nom)
59
+ else:
60
+ st.warning("Entrez un nom d'abord.")
61
 
62
+ # ÉTAPE 2 : Le champ de texte est ICI (modifiable)
63
+ script_final = st.text_area("📝 Script de la vidéo (Vérifiez et modifiez)",
64
+ value=st.session_state['script'],
65
+ height=150)
66
 
67
+ # ÉTAPE 3 : Générer
68
+ if st.button("🎬 2. CRÉER LA VIDÉO"):
69
+ if nom and script_final:
70
+ with st.spinner("Génération du fichier MP4..."):
71
+ v = fabriquer_video(nom, script_final)
72
+ if v:
73
+ st.video(v)
74
+ st.success("Vidéo générée avec succès !")
75
+ with open(v, "rb") as f:
76
+ st.download_button("📥 Télécharger", f, file_name=f"{nom}.mp4")
 
 
 
 
77
  else:
78
+ st.error("Le nom et le script sont obligatoires.")