Adjoumani commited on
Commit
759021b
·
verified ·
1 Parent(s): afeee8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -4
app.py CHANGED
@@ -908,6 +908,20 @@ def get_transcription(file_path=None, audio_bytes=None) -> str:
908
 
909
  return " ".join(transcriptions) if transcriptions else None
910
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
911
  def display_transcription_and_summary(transcription: str):
912
  """Affichage de la transcription et du résumé"""
913
  st.subheader("Transcription")
@@ -918,7 +932,7 @@ def display_transcription_and_summary(transcription: str):
918
  st.markdown(summary)
919
 
920
  # Génération et téléchargement des documents
921
- generate_and_download_documents(summary)
922
 
923
  # Option d'envoi par email
924
  handle_email_sending(summary)
@@ -930,8 +944,8 @@ def get_summary(transcription: str) -> str:
930
  return st.session_state.audio_processor.summarize_long_transcription(transcription)
931
  return st.session_state.audio_processor.generate_summary(transcription)
932
 
933
- def generate_and_download_documents(summary: str):
934
- """Génération et téléchargement des documents"""
935
  timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
936
 
937
  # Génération PDF
@@ -962,6 +976,41 @@ def generate_and_download_documents(summary: str):
962
  mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
963
  )
964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965
  return pdf_path
966
 
967
  def handle_email_sending(summary: str):
@@ -1064,6 +1113,34 @@ def display_summary_and_downloads(summary: str):
1064
  st.markdown("### 📝 Résumé et Analyse")
1065
  st.markdown(summary)
1066
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1067
  timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
1068
 
1069
  # Génération PDF
@@ -1112,7 +1189,7 @@ def display_summary_and_downloads(summary: str):
1112
  ):
1113
  st.success("Email envoyé avec succès!")
1114
  else:
1115
- st.error("Échec de l'envoi de l'email.")
1116
 
1117
  def save_audio_bytes(audio_bytes: bytes) -> str:
1118
  """Sauvegarde les bytes audio dans un fichier temporaire"""
 
908
 
909
  return " ".join(transcriptions) if transcriptions else None
910
 
911
+ """def display_transcription_and_summary(transcription: str):
912
+ #Affichage de la transcription et du résumé
913
+ st.subheader("Transcription")
914
+ st.text_area("Texte transcrit:", value=transcription, height=200)
915
+
916
+ st.subheader("Résumé et Analyse")
917
+ summary = get_summary(transcription)
918
+ st.markdown(summary)
919
+
920
+ # Génération et téléchargement des documents
921
+ generate_and_download_documents(summary)
922
+
923
+ # Option d'envoi par email
924
+ handle_email_sending(summary)"""
925
  def display_transcription_and_summary(transcription: str):
926
  """Affichage de la transcription et du résumé"""
927
  st.subheader("Transcription")
 
932
  st.markdown(summary)
933
 
934
  # Génération et téléchargement des documents
935
+ generate_and_download_documents(summary, "transcription")
936
 
937
  # Option d'envoi par email
938
  handle_email_sending(summary)
 
944
  return st.session_state.audio_processor.summarize_long_transcription(transcription)
945
  return st.session_state.audio_processor.generate_summary(transcription)
946
 
947
+ """def generate_and_download_documents(summary: str):
948
+ #Génération et téléchargement des documents
949
  timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
950
 
951
  # Génération PDF
 
976
  mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
977
  )
978
 
979
+ return pdf_path"""
980
+ def generate_and_download_documents(summary: str, context="main"):
981
+ """Génération et téléchargement des documents"""
982
+ timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
983
+
984
+ # Génération PDF
985
+ pdf_filename = f"resume_{timestamp}.pdf"
986
+ pdf_path = PDFGenerator.create_pdf(summary, pdf_filename)
987
+
988
+ # Génération DOCX
989
+ docx_filename = f"resume_{timestamp}.docx"
990
+ docx_path = generate_docx(summary, docx_filename)
991
+
992
+ # Boutons de téléchargement
993
+ col1, col2 = st.columns(2)
994
+ with col1:
995
+ with open(pdf_path, "rb") as pdf_file:
996
+ st.download_button(
997
+ "📥 Télécharger PDF",
998
+ pdf_file,
999
+ file_name=pdf_filename,
1000
+ mime="application/pdf",
1001
+ key=f"pdf_download_{context}"
1002
+ )
1003
+
1004
+ with col2:
1005
+ with open(docx_path, "rb") as docx_file:
1006
+ st.download_button(
1007
+ "📥 Télécharger DOCX",
1008
+ docx_file,
1009
+ file_name=docx_filename,
1010
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1011
+ key=f"docx_download_{context}"
1012
+ )
1013
+
1014
  return pdf_path
1015
 
1016
  def handle_email_sending(summary: str):
 
1113
  st.markdown("### 📝 Résumé et Analyse")
1114
  st.markdown(summary)
1115
 
1116
+ # Génération et téléchargement avec un contexte différent
1117
+ pdf_path = generate_and_download_documents(summary, "document")
1118
+
1119
+ # Option d'envoi par email
1120
+ st.markdown("### 📧 Recevoir le résumé par email")
1121
+ recipient_email = st.text_input("Entrez votre adresse email:", key="email_input")
1122
+
1123
+ if st.button("Envoyer par email", key="send_email_btn"):
1124
+ if not is_valid_email(recipient_email):
1125
+ st.error("Veuillez entrer une adresse email valide.")
1126
+ else:
1127
+ with st.spinner("Envoi de l'email en cours..."):
1128
+ email_sender = EmailSender(Config.SENDER_EMAIL, Config.SENDER_PASSWORD)
1129
+ if email_sender.send_email(
1130
+ recipient_email,
1131
+ "Résumé de votre contenu",
1132
+ "Veuillez trouver ci-joint le résumé de votre contenu.",
1133
+ pdf_path
1134
+ ):
1135
+ st.success("Email envoyé avec succès!")
1136
+ else:
1137
+ st.error("Échec de l'envoi de l'email.")
1138
+
1139
+ """def display_summary_and_downloads(summary: str):
1140
+ #Affichage du résumé et options de téléchargement
1141
+ st.markdown("### 📝 Résumé et Analyse")
1142
+ st.markdown(summary)
1143
+
1144
  timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
1145
 
1146
  # Génération PDF
 
1189
  ):
1190
  st.success("Email envoyé avec succès!")
1191
  else:
1192
+ st.error("Échec de l'envoi de l'email.")"""
1193
 
1194
  def save_audio_bytes(audio_bytes: bytes) -> str:
1195
  """Sauvegarde les bytes audio dans un fichier temporaire"""