Update app.py
Browse files179 unmodified lines1801811821831841851861871881891901911921931941951961971981992001 unmodified line202203204205206207208209210211212213214215179 unmodified linesdef format_to_markdown(transcription_text, speaker_transcription, audio_duration=None, location=None, speaker_age=None, context=None, num_speakers=None, speaker_names=None):metadata = {"Date de traitement": datetime.now().strftime('%d/%m/%Y %H:%M'),"Durée de l'audio": f"{audio_duration} secondes" if audio_duration else "[à remplir]","Lieu": location if location else "[non spécifié]","Nombre d'interlocuteurs": num_speakers if num_speakers else "[non spécifié]","Âge de l'intervenant": f"{speaker_age} ans" if speaker_age else "[non spécifié]","Contexte": context if context else "[non spécifié]"}# Gestion plus robuste de speaker_namesif speaker_names is not None:if isinstance(speaker_names, list):for item in speaker_names:if isinstance(item, (list, tuple)) and len(item) == 2:metadata[item[0]] = item[1]elif isinstance(item, dict) and "Speaker ID" in item and "Nom personnalisé" in item:metadata[item["Speaker ID"]] = item["Nom personnalisé"]metadata_text = "\n".join([f"- **{key}** : '{value}'" for key, value in metadata.items()])1 unmodified lineif isinstance(speaker_transcription, str):speaker_transcription = parse_simplified_diarization(speaker_transcription)if isinstance(speaker_transcription, list) and all(isinstance(item, tuple) and len(item) == 2 for item in speaker_transcription):formatted_transcription = []for speaker, text in speaker_transcription:custom_name = next((item[1] for item in speaker_names if item[0] == speaker), speaker) if isinstance(speaker_names, list) else speakerformatted_transcription.append(f"**{custom_name}**: {text}")transcription_text = "\n\n".join(formatted_transcription)else:raise ValueError("Invalid speaker transcription format")except Exception as e:print(f"Error formatting speaker transcription: {e}")transcription_text = "Error formatting speaker transcription. Using raw transcription instead.\n\n" + transcription_text179 unmodified lines1801811821831841851861871881891901911921931941951961971981992002012022031 unmodified line205206207208209210211212213214215179 unmodified linesdef format_to_markdown(transcription_text, speaker_transcription, audio_duration=None, location=None, speaker_age=None, context=None, num_speakers=None, speaker_names=None):metadata = {"Date de traitement": datetime.now().strftime('%d/%m/%Y %H:%M'),"Durée de l'audio": f"{audio_duration}" if audio_duration else "[à remplir]","Lieu": location if location else "[non spécifié]","Nombre d'interlocuteurs": num_speakers if num_speakers else "[non spécifié]","Âge de l'intervenant": f"{speaker_age} ans" if speaker_age else "[non spécifié]","Contexte": context if context else "[non spécifié]"}# Créer un dictionnaire pour les noms personnaliséscustom_names = {}if speaker_names is not None:for row in speaker_names:if isinstance(row, dict):speaker_id = row.get("Speaker ID")custom_name = row.get("Nom personnalisé")if speaker_id and custom_name:custom_names[speaker_id] = custom_nameelif isinstance(row, (list, tuple)) and len(row) == 2:custom_names[row[0]] = row[1]metadata_text = "\n".join([f"- **{key}** : '{value}'" for key, value in metadata.items()])1 unmodified lineif isinstance(speaker_transcription, str):speaker_transcription = parse_simplified_diarization(speaker_transcription)formatted_transcription = []for speaker, text in speaker_transcription:custom_name = custom_names.get(speaker, speaker)formatted_transcription.append(f"**{custom_name}**: {text}")transcription_text = "\n\n".join(formatted_transcription)except Exception as e:print(f"Error formatting speaker transcription: {e}")transcription_text = "Error formatting speaker transcription. Using raw transcription instead.\n\n" + transcription_text
app.py+16-16