|
|
|
|
|
""" |
|
|
Application principale pour Hugging Face Space |
|
|
""" |
|
|
|
|
|
import gradio as gr |
|
|
import os |
|
|
import tempfile |
|
|
from pathlib import Path |
|
|
import sys |
|
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(__file__)) |
|
|
|
|
|
|
|
|
try: |
|
|
from transcribe_audio import transcribe_file, load_whisper_model, get_audio_files |
|
|
from analyze_bob_hf import analyze_files_hf |
|
|
print("✅ Modules importés avec succès") |
|
|
except Exception as e: |
|
|
print(f"❌ Erreur d'import: {e}") |
|
|
|
|
|
def process_audio_file(audio_file): |
|
|
"""Traite un fichier audio et retourne les résultats""" |
|
|
try: |
|
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir: |
|
|
temp_path = Path(temp_dir) |
|
|
input_dir = temp_path / "input" |
|
|
output_dir = temp_path / "output" |
|
|
transcriptions_dir = output_dir / "transcriptions" |
|
|
|
|
|
input_dir.mkdir(parents=True, exist_ok=True) |
|
|
output_dir.mkdir(parents=True, exist_ok=True) |
|
|
transcriptions_dir.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
|
|
|
audio_path = input_dir / os.path.basename(audio_file) |
|
|
import shutil |
|
|
shutil.copy2(audio_file, audio_path) |
|
|
|
|
|
|
|
|
os.environ["BOB_INPUT_DIR"] = str(input_dir) |
|
|
os.environ["BOB_TRANSCRIPTIONS_DIR"] = str(transcriptions_dir) |
|
|
os.environ["BOB_OUTPUT_FILE"] = str(output_dir / "resume_bob.txt") |
|
|
os.environ["WHISPER_MODEL"] = "small" |
|
|
|
|
|
|
|
|
print("🔄 Transcription en cours...") |
|
|
model = load_whisper_model("small") |
|
|
success = transcribe_file(model, audio_path, transcriptions_dir) |
|
|
|
|
|
if not success: |
|
|
return "❌ Erreur de transcription", "" |
|
|
|
|
|
|
|
|
print("🤖 Analyse en cours...") |
|
|
result = analyze_files_hf( |
|
|
transcriptions_dir=transcriptions_dir, |
|
|
input_dir=input_dir, |
|
|
output_file=output_dir / "resume_bob.txt", |
|
|
log_fn=print |
|
|
) |
|
|
|
|
|
|
|
|
resume_path = output_dir / "resume_bob.txt" |
|
|
if resume_path.exists(): |
|
|
with open(resume_path, 'r', encoding='utf-8') as f: |
|
|
resume_content = f.read() |
|
|
else: |
|
|
resume_content = "❌ Fichier de résultat non trouvé" |
|
|
|
|
|
|
|
|
transcription_files = list(transcriptions_dir.glob("*.txt")) |
|
|
if transcription_files: |
|
|
with open(transcription_files[0], 'r', encoding='utf-8') as f: |
|
|
transcription_content = f.read() |
|
|
else: |
|
|
transcription_content = "❌ Transcription non trouvée" |
|
|
|
|
|
return transcription_content, resume_content |
|
|
|
|
|
except Exception as e: |
|
|
return f"❌ Erreur: {str(e)}", f"❌ Erreur: {str(e)}" |
|
|
|
|
|
|
|
|
with gr.Blocks(title="BOB Processor") as demo: |
|
|
gr.Markdown("# 🎵 BOB Processor") |
|
|
gr.Markdown("### Transcription et analyse automatique de fichiers audio") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
audio_input = gr.Audio( |
|
|
label="🎤 Fichier audio à traiter", |
|
|
type="filepath" |
|
|
) |
|
|
process_btn = gr.Button("▶️ Traiter le fichier") |
|
|
|
|
|
with gr.Column(): |
|
|
transcription_output = gr.Textbox( |
|
|
label="📝 Transcription", |
|
|
lines=10 |
|
|
) |
|
|
resume_output = gr.Textbox( |
|
|
label="📋 Résumé analysé", |
|
|
lines=10 |
|
|
) |
|
|
|
|
|
process_btn.click( |
|
|
process_audio_file, |
|
|
inputs=[audio_input], |
|
|
outputs=[transcription_output, resume_output] |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|