Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -931,6 +931,41 @@ def get_summary(full_transcription):
|
|
931 |
|
932 |
return summary # Retourne le résumé
|
933 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
934 |
|
935 |
|
936 |
def display_transcription_and_summary(transcription: str):
|
@@ -943,15 +978,37 @@ def display_transcription_and_summary(transcription: str):
|
|
943 |
st.markdown(summary)
|
944 |
|
945 |
# Génération et téléchargement des documents
|
946 |
-
|
947 |
|
948 |
# Option d'envoi par email
|
949 |
-
|
950 |
-
|
951 |
|
952 |
|
953 |
|
954 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
955 |
|
956 |
|
957 |
|
@@ -979,7 +1036,12 @@ def process_document():
|
|
979 |
text = process_document_with_password(file, password, doc_processor)
|
980 |
if text:
|
981 |
summary = doc_processor.summarize_text(text)
|
982 |
-
|
|
|
|
|
|
|
|
|
|
|
983 |
except ValueError as e:
|
984 |
st.error(str(e))
|
985 |
|
@@ -1025,62 +1087,6 @@ def process_web():
|
|
1025 |
except ValueError as e:
|
1026 |
st.error(str(e))
|
1027 |
|
1028 |
-
def display_summary_and_downloads(summary: str):
|
1029 |
-
"""Affichage du résumé et options de téléchargement"""
|
1030 |
-
st.markdown("### 📝 Résumé et Analyse")
|
1031 |
-
st.markdown(summary)
|
1032 |
-
|
1033 |
-
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
1034 |
-
|
1035 |
-
# Génération PDF
|
1036 |
-
pdf_filename = f"resume_{timestamp}.pdf"
|
1037 |
-
pdf_path = PDFGenerator.create_pdf(summary, pdf_filename)
|
1038 |
-
|
1039 |
-
# Génération DOCX
|
1040 |
-
docx_filename = f"resume_{timestamp}.docx"
|
1041 |
-
docx_path = generate_docx(summary, docx_filename)
|
1042 |
-
|
1043 |
-
# Boutons de téléchargement avec des clés uniques
|
1044 |
-
col1, col2 = st.columns(2)
|
1045 |
-
with col1:
|
1046 |
-
with open(pdf_path, "rb") as pdf_file:
|
1047 |
-
st.download_button(
|
1048 |
-
"📥 Télécharger PDF",
|
1049 |
-
pdf_file,
|
1050 |
-
file_name=pdf_filename,
|
1051 |
-
mime="application/pdf",
|
1052 |
-
key=f"display_download_pdf_{uuid.uuid4()}" # Clé unique basée sur UUID
|
1053 |
-
)
|
1054 |
-
|
1055 |
-
with col2:
|
1056 |
-
with open(docx_path, "rb") as docx_file:
|
1057 |
-
st.download_button(
|
1058 |
-
"📥 Télécharger DOCX",
|
1059 |
-
docx_file,
|
1060 |
-
file_name=docx_filename,
|
1061 |
-
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
1062 |
-
key=f"display_download_docx_{uuid.uuid4()}" # Clé unique basée sur UUID
|
1063 |
-
)
|
1064 |
-
|
1065 |
-
# Option d'envoi par email
|
1066 |
-
st.markdown("### 📧 Recevoir le résumé par email")
|
1067 |
-
recipient_email = st.text_input("Entrez votre adresse email:")
|
1068 |
-
|
1069 |
-
if st.button("Envoyer par email"):
|
1070 |
-
if not is_valid_email(recipient_email):
|
1071 |
-
st.error("Veuillez entrer une adresse email valide.")
|
1072 |
-
else:
|
1073 |
-
with st.spinner("Envoi de l'email en cours..."):
|
1074 |
-
email_sender = EmailSender(SENDER_EMAIL, SENDER_PASSWORD)
|
1075 |
-
if email_sender.send_email(
|
1076 |
-
recipient_email,
|
1077 |
-
"Résumé de votre contenu",
|
1078 |
-
"Veuillez trouver ci-joint le résumé de votre contenu.",
|
1079 |
-
pdf_path
|
1080 |
-
):
|
1081 |
-
st.success("Email envoyé avec succès!")
|
1082 |
-
else:
|
1083 |
-
st.error("Échec de l'envoi de l'email.")
|
1084 |
|
1085 |
|
1086 |
|
|
|
931 |
|
932 |
return summary # Retourne le résumé
|
933 |
|
934 |
+
def generate_and_download_documents(summary: str):
|
935 |
+
"""Génération et téléchargement des documents"""
|
936 |
+
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
937 |
+
|
938 |
+
# Génération PDF
|
939 |
+
pdf_filename = f"resume_{timestamp}.pdf"
|
940 |
+
pdf_path = PDFGenerator.create_pdf(summary, pdf_filename)
|
941 |
+
|
942 |
+
# Génération DOCX
|
943 |
+
docx_filename = f"resume_{timestamp}.docx"
|
944 |
+
docx_path = generate_docx(summary, docx_filename)
|
945 |
+
|
946 |
+
# Boutons de téléchargement avec des clés uniques
|
947 |
+
col1, col2 = st.columns(2)
|
948 |
+
with col1:
|
949 |
+
with open(pdf_path, "rb") as pdf_file:
|
950 |
+
st.download_button(
|
951 |
+
"📥 Télécharger PDF",
|
952 |
+
pdf_file,
|
953 |
+
file_name=pdf_filename,
|
954 |
+
mime="application/pdf",
|
955 |
+
key=f"download_pdf_{uuid.uuid4()}" # Utilisation d'un UUID
|
956 |
+
)
|
957 |
+
|
958 |
+
with col2:
|
959 |
+
with open(docx_path, "rb") as docx_file:
|
960 |
+
st.download_button(
|
961 |
+
"📥 Télécharger DOCX",
|
962 |
+
docx_file,
|
963 |
+
file_name=docx_filename,
|
964 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
965 |
+
key=f"download_docx_{uuid.uuid4()}" # Utilisation d'un UUID
|
966 |
+
)
|
967 |
+
|
968 |
+
return pdf_path
|
969 |
|
970 |
|
971 |
def display_transcription_and_summary(transcription: str):
|
|
|
978 |
st.markdown(summary)
|
979 |
|
980 |
# Génération et téléchargement des documents
|
981 |
+
generate_and_download_documents(summary)
|
982 |
|
983 |
# Option d'envoi par email
|
984 |
+
handle_email_sending(summary)
|
|
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
+
def handle_email_sending(summary: str):
|
990 |
+
"""Gestion de l'envoi par email"""
|
991 |
+
st.subheader("📧 Recevoir le résumé par email")
|
992 |
+
recipient_email = st.text_input("Entrez votre adresse email:")
|
993 |
+
|
994 |
+
if st.button("Envoyer par email"):
|
995 |
+
if not is_valid_email(recipient_email):
|
996 |
+
st.error("Veuillez entrer une adresse email valide.")
|
997 |
+
return
|
998 |
+
|
999 |
+
with st.spinner("Envoi de l'email en cours..."):
|
1000 |
+
pdf_path = generate_and_download_documents(summary)
|
1001 |
+
email_sender = EmailSender(SENDER_EMAIL, SENDER_PASSWORD)
|
1002 |
+
|
1003 |
+
if email_sender.send_email(
|
1004 |
+
recipient_email,
|
1005 |
+
"Résumé de votre contenu audio/vidéo",
|
1006 |
+
"Veuillez trouver ci-joint le résumé de votre contenu.",
|
1007 |
+
pdf_path
|
1008 |
+
):
|
1009 |
+
st.success("Email envoyé avec succès!")
|
1010 |
+
else:
|
1011 |
+
st.error("Échec de l'envoi de l'email.")
|
1012 |
|
1013 |
|
1014 |
|
|
|
1036 |
text = process_document_with_password(file, password, doc_processor)
|
1037 |
if text:
|
1038 |
summary = doc_processor.summarize_text(text)
|
1039 |
+
# Génération et téléchargement des documents
|
1040 |
+
#generate_and_download_documents(summary)
|
1041 |
+
|
1042 |
+
# Option d'envoi par email
|
1043 |
+
handle_email_sending(summary)
|
1044 |
+
#display_summary_and_downloads(summary)
|
1045 |
except ValueError as e:
|
1046 |
st.error(str(e))
|
1047 |
|
|
|
1087 |
except ValueError as e:
|
1088 |
st.error(str(e))
|
1089 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1090 |
|
1091 |
|
1092 |
|