PrismeFoot commited on
Commit
0374729
·
verified ·
1 Parent(s): cbee46f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -37
app.py CHANGED
@@ -42,63 +42,41 @@ def obtenir_image_fond(sujet):
42
  return "color=black@0.5:s=720x1280"
43
 
44
  # --- MOTEUR DE PRODUCTION ---
 
 
45
  async def creer_video_expert(joueur, news_brute):
46
- # 1. ON DÉFINIT LES NOMS DE FICHIERS ICI (TRÈS IMPORTANT)
47
  uid = uuid.uuid4().hex[:6]
48
  audio_file = f"audio_{uid}.mp3"
49
- srt_file = f"subs_{uid}.srt"
50
  video_final = f"PRISME_{uid}.mp4"
51
 
52
- # 2. Sécurité : Texte par défaut si l'IA a buggé
53
  script = f"Alerte Info ! {news_brute} Abonne-toi à Prisme Foot !"
54
- if not news_brute or len(news_brute) < 5:
55
- script = f"Alerte Info ! {joueur} choque le monde du football. Abonne-toi !"
56
-
57
- # 3. Tentative de génération audio
58
- success_audio = False
59
- for tentative in range(3):
60
- try:
61
- communicate = edge_tts.Communicate(script, VOIX_FR)
62
- submaker = edge_tts.SubMaker()
63
-
64
- with open(audio_file, "wb") as f:
65
- async for chunk in communicate.stream():
66
- if chunk["type"] == "audio": f.write(chunk["data"])
67
- elif chunk["type"] == "WordBoundary": submaker.feed(chunk)
68
-
69
- with open(srt_file, "w", encoding="utf-8") as f:
70
- f.write(submaker.generate())
71
-
72
- success_audio = True
73
- break
74
- except Exception as e:
75
- st.warning(f"Tentative audio {tentative+1}/3...")
76
- await asyncio.sleep(1)
77
-
78
- if not success_audio:
79
  return None
80
 
81
- # 4. Image de fond
82
  image_path = obtenir_image_fond(joueur)
83
  input_source = f'-i "{image_path}"' if not image_path.startswith("color") else f'-f lavfi -i "{image_path}"'
84
 
85
- # 5. Montage FFmpeg
86
- style = "Alignment=10,FontSize=28,PrimaryColour=&H00FFFF,OutlineColour=&H000000,BorderStyle=3"
87
  cmd = (
88
  f'ffmpeg -loop 1 {input_source} -i {audio_file} '
89
  f'-vf "scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,'
90
  f'zoompan=z=\'min(zoom+0.0015,1.5)\':d=125:s=720x1280,'
91
- f'subtitles={srt_file}:force_style=\'{style}\'" '
92
  f'-c:v libx264 -preset superfast -tune stillimage -c:a aac -shortest {video_final} -y'
93
  )
94
 
95
  subprocess.run(cmd, shell=True)
96
 
97
- # Nettoyage
98
- for f in [audio_file, srt_file]:
99
- if os.path.exists(f): os.remove(f)
100
-
101
- return video_final
102
  # --- INTERFACE STREAMLIT ---
103
  st.set_page_config(page_title="Prisme Foot AI", page_icon="⚽")
104
  st.title("⚽ Prisme Foot : Studio IA")
 
42
  return "color=black@0.5:s=720x1280"
43
 
44
  # --- MOTEUR DE PRODUCTION ---
45
+ from gtts import gTTS # Ajoute cet import en haut du fichier
46
+
47
  async def creer_video_expert(joueur, news_brute):
 
48
  uid = uuid.uuid4().hex[:6]
49
  audio_file = f"audio_{uid}.mp3"
 
50
  video_final = f"PRISME_{uid}.mp4"
51
 
52
+ # 1. Texte de sécurité
53
  script = f"Alerte Info ! {news_brute} Abonne-toi à Prisme Foot !"
54
+
55
+ # 2. Génération Audio avec gTTS (Très stable)
56
+ try:
57
+ tts = gTTS(text=script, lang='fr')
58
+ tts.save(audio_file)
59
+ except Exception as e:
60
+ st.error(f"Erreur Audio : {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  return None
62
 
63
+ # 3. Image de fond
64
  image_path = obtenir_image_fond(joueur)
65
  input_source = f'-i "{image_path}"' if not image_path.startswith("color") else f'-f lavfi -i "{image_path}"'
66
 
67
+ # 4. Montage FFmpeg (On retire les sous-titres temporairement pour isoler le problème)
 
68
  cmd = (
69
  f'ffmpeg -loop 1 {input_source} -i {audio_file} '
70
  f'-vf "scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,'
71
  f'zoompan=z=\'min(zoom+0.0015,1.5)\':d=125:s=720x1280,'
72
+ f'drawtext=text=\'PRISME FOOT\':fontcolor=yellow:fontsize=45:x=(w-text_w)/2:y=150:box=1:boxcolor=black@0.6" '
73
  f'-c:v libx264 -preset superfast -tune stillimage -c:a aac -shortest {video_final} -y'
74
  )
75
 
76
  subprocess.run(cmd, shell=True)
77
 
78
+ if os.path.exists(audio_file): os.remove(audio_file)
79
+ return video_final if os.path.exists(video_final) else None
 
 
 
80
  # --- INTERFACE STREAMLIT ---
81
  st.set_page_config(page_title="Prisme Foot AI", page_icon="⚽")
82
  st.title("⚽ Prisme Foot : Studio IA")