Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -455,60 +455,7 @@ class VideoProcessor:
|
|
455 |
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")
|
456 |
|
457 |
|
458 |
-
"""def download_youtube_audio(self, url: str) -> str:
|
459 |
-
try:
|
460 |
-
# Définir le chemin vers le fichier cookies
|
461 |
-
cookie_file_path = "cookies.txt" # Assurez-vous que le fichier est dans le bon dossier
|
462 |
-
|
463 |
-
# Chemin de sortie pour l'audio
|
464 |
-
audio_file_path = "temp_audio.mp3"
|
465 |
-
|
466 |
-
# Options pour yt-dlp
|
467 |
-
ydl_opts = {
|
468 |
-
'format': 'bestaudio/best',
|
469 |
-
'postprocessors': [{
|
470 |
-
'key': 'FFmpegExtractAudio',
|
471 |
-
'preferredcodec': 'mp3',
|
472 |
-
'preferredquality': '192',
|
473 |
-
}],
|
474 |
-
'outtmpl': audio_file_path, # Fichier de sortie
|
475 |
-
'cookiefile': cookie_file_path # Utilisation du fichier de cookies
|
476 |
-
}
|
477 |
-
|
478 |
-
# Téléchargement de l'audio
|
479 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
480 |
-
ydl.download([url])
|
481 |
|
482 |
-
# Retourner le chemin du fichier téléchargé
|
483 |
-
return audio_file_path
|
484 |
-
except Exception as e:
|
485 |
-
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")"""
|
486 |
-
|
487 |
-
|
488 |
-
"""def download_youtube_audio(self, url: str) -> str:
|
489 |
-
"""
|
490 |
-
#Télécharge une vidéo YouTube en utilisant les cookies du navigateur.
|
491 |
-
"""
|
492 |
-
ydl_opts = {
|
493 |
-
'cookiesfrombrowser': ('chrome',), # Utilise Chromium pour les cookies
|
494 |
-
'format': 'bestaudio/best',
|
495 |
-
'postprocessors': [
|
496 |
-
{
|
497 |
-
'key': 'FFmpegExtractAudio',
|
498 |
-
'preferredcodec': 'mp3',
|
499 |
-
}
|
500 |
-
],
|
501 |
-
'outtmpl': 'temp_audio_with_cookies.%(ext)s'
|
502 |
-
}
|
503 |
-
|
504 |
-
try:
|
505 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
506 |
-
ydl.download([url])
|
507 |
-
return 'temp_audio_with_cookies.mp3'
|
508 |
-
except Exception as e:
|
509 |
-
st.error(f"Erreur lors du téléchargement de la vidéo avec cookies : {str(e)}")
|
510 |
-
raise
|
511 |
-
"""
|
512 |
|
513 |
def extract_audio_from_video(self, video_path: str) -> str:
|
514 |
try:
|
@@ -525,7 +472,7 @@ class DocumentProcessor:
|
|
525 |
self.llm = ChatGroq(
|
526 |
model=model_name,
|
527 |
temperature=0,
|
528 |
-
api_key=Config.GROQ_API_KEY
|
529 |
)
|
530 |
self.custom_prompt = prompt
|
531 |
#self.text_splitter = RecursiveCharacterTextSplitter(
|
@@ -552,7 +499,7 @@ class DocumentProcessor:
|
|
552 |
"""Traduit le texte en français si nécessaire"""
|
553 |
try:
|
554 |
messages = [
|
555 |
-
SystemMessage(content="Vous êtes un traducteur professionnel. Traduisez le texte suivant en français en conservant le format et la structure:"),
|
556 |
HumanMessage(content=text)
|
557 |
]
|
558 |
result = self._make_api_call(messages)
|
@@ -651,23 +598,7 @@ class DocumentProcessor:
|
|
651 |
except Exception as e:
|
652 |
raise RuntimeError(f"Erreur lors du traitement du fichier Office : {e}")
|
653 |
|
654 |
-
|
655 |
-
try:
|
656 |
-
office_file = msoffcrypto.OfficeFile(file)
|
657 |
-
office_file.load_key(password=password)
|
658 |
-
|
659 |
-
decrypted = io.BytesIO()
|
660 |
-
office_file.decrypt(decrypted)
|
661 |
-
|
662 |
-
if file_type == 'docx':
|
663 |
-
doc = docx.Document(decrypted)
|
664 |
-
return "\n".join([p.text for p in doc.paragraphs])
|
665 |
-
elif file_type == 'pptx':
|
666 |
-
ppt = pptx.Presentation(decrypted)
|
667 |
-
return "\n".join([shape.text for slide in ppt.slides
|
668 |
-
for shape in slide.shapes if hasattr(shape, "text")])
|
669 |
-
except Exception:
|
670 |
-
raise ValueError("Mot de passe document incorrect")"""
|
671 |
|
672 |
def scrape_web_content(self, url: str, auth: Dict[str, str] = None) -> str:
|
673 |
try:
|
@@ -747,31 +678,7 @@ class DocumentProcessor:
|
|
747 |
time.sleep(60)
|
748 |
return self.summarize_long_transcription(transcription)
|
749 |
raise e
|
750 |
-
|
751 |
-
try:
|
752 |
-
chunks = self.text_splitter.split_text(text)
|
753 |
-
summaries = []
|
754 |
-
|
755 |
-
for chunk in chunks:
|
756 |
-
messages = [
|
757 |
-
SystemMessage(content="Générez un résumé en français de ce texte:"),
|
758 |
-
HumanMessage(content=chunk)
|
759 |
-
]
|
760 |
-
summary = self._make_api_call(messages).generations[0][0].text
|
761 |
-
summaries.append(summary)
|
762 |
-
|
763 |
-
if len(summaries) > 1:
|
764 |
-
final_messages = [
|
765 |
-
SystemMessage(content="Combinez ces résum��s en un résumé cohérent en français:"),
|
766 |
-
HumanMessage(content="\n".join(summaries))
|
767 |
-
]
|
768 |
-
final_summary = self._make_api_call(final_messages).generations[0][0].text
|
769 |
-
return final_summary
|
770 |
-
|
771 |
-
return summaries[0]
|
772 |
-
|
773 |
-
except Exception as e:
|
774 |
-
raise ValueError(f"Erreur de traitement: {str(e)}")"""
|
775 |
|
776 |
def generate_docx(content: str, filename: str):
|
777 |
doc = Document()
|
|
|
455 |
raise RuntimeError(f"Erreur lors du téléchargement : {str(e)}")
|
456 |
|
457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
def extract_audio_from_video(self, video_path: str) -> str:
|
461 |
try:
|
|
|
472 |
self.llm = ChatGroq(
|
473 |
model=model_name,
|
474 |
temperature=0,
|
475 |
+
#api_key=Config.GROQ_API_KEY
|
476 |
)
|
477 |
self.custom_prompt = prompt
|
478 |
#self.text_splitter = RecursiveCharacterTextSplitter(
|
|
|
499 |
"""Traduit le texte en français si nécessaire"""
|
500 |
try:
|
501 |
messages = [
|
502 |
+
SystemMessage(content="Vous êtes un traducteur professionnel agrée en Français. Traduisez le texte suivant en français en conservant le format et la structure:"),
|
503 |
HumanMessage(content=text)
|
504 |
]
|
505 |
result = self._make_api_call(messages)
|
|
|
598 |
except Exception as e:
|
599 |
raise RuntimeError(f"Erreur lors du traitement du fichier Office : {e}")
|
600 |
|
601 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
|
603 |
def scrape_web_content(self, url: str, auth: Dict[str, str] = None) -> str:
|
604 |
try:
|
|
|
678 |
time.sleep(60)
|
679 |
return self.summarize_long_transcription(transcription)
|
680 |
raise e
|
681 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
682 |
|
683 |
def generate_docx(content: str, filename: str):
|
684 |
doc = Document()
|