ZELEFACK commited on
Commit
f9d96c0
1 Parent(s): 78f64bc

supprime le fichier

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -70,16 +70,25 @@ def generate_summary(file_name, mode,final_language):
70
  global cnt
71
  sentences = read_article(file_name)
72
  translator = Translator()
73
- cnt +=1
74
  if mode == "traduction":
75
  text_translate = translate_data(sentences,final_language)
76
  myobj = gTTS(text=text_translate, lang=get_key(final_language), slow=False)
 
 
 
 
 
77
  myobj.save(f"audio_traduce{cnt}.wav")
78
  return f"audio_traduce{cnt}.wav", text_translate
79
  elif mode=="lecture":
80
  text = translator.translate(sentences)
81
  text_translate = sentences
82
  myobj = gTTS(text=text_translate, lang=get_key(final_language), slow=False)
 
 
 
 
83
  myobj.save(f"audio_lecture{cnt}.wav")
84
  return f"audio_lecture{cnt}.wav", text_translate
85
  elif mode == "resume_et_traduire":
@@ -88,6 +97,10 @@ def generate_summary(file_name, mode,final_language):
88
  text = translate_data(text_translate,final_language)
89
  text_translate = text
90
  myobj = gTTS(text=text, lang=get_key(final_language), slow=False)
 
 
 
 
91
  myobj.save(f"audio_resume_traduire{cnt}.wav")
92
  return f"audio_resume_traduire{cnt}.wav", text_translate
93
  else:
@@ -95,6 +108,10 @@ def generate_summary(file_name, mode,final_language):
95
  text_translate = text_translate[0]['summary_text']
96
  text = translator.translate(text_translate)
97
  myobj = gTTS(text=text_translate, lang=text.src, slow=False)
 
 
 
 
98
  myobj.save(f"audio_resume{cnt}.wav")
99
  return f"audio_resume{cnt}.wav", text_translate
100
 
 
70
  global cnt
71
  sentences = read_article(file_name)
72
  translator = Translator()
73
+ # cnt +=1
74
  if mode == "traduction":
75
  text_translate = translate_data(sentences,final_language)
76
  myobj = gTTS(text=text_translate, lang=get_key(final_language), slow=False)
77
+ #nous devrions vérifier si le fichier existe ou non avant de le supprimer.
78
+ if os.path.exists(f"audio_traduce{cnt}.wav"):
79
+ os.remove(f"audio_traduce{cnt}.wav")
80
+ else:
81
+ print("Impossible de supprimer le fichier car il n'existe pas")
82
  myobj.save(f"audio_traduce{cnt}.wav")
83
  return f"audio_traduce{cnt}.wav", text_translate
84
  elif mode=="lecture":
85
  text = translator.translate(sentences)
86
  text_translate = sentences
87
  myobj = gTTS(text=text_translate, lang=get_key(final_language), slow=False)
88
+ if os.path.exists(f"audio_lecture{cnt}.wav"):
89
+ os.remove(f"audio_lecture{cnt}.wav")
90
+ else:
91
+ print("Impossible de supprimer le fichier car il n'existe pas")
92
  myobj.save(f"audio_lecture{cnt}.wav")
93
  return f"audio_lecture{cnt}.wav", text_translate
94
  elif mode == "resume_et_traduire":
 
97
  text = translate_data(text_translate,final_language)
98
  text_translate = text
99
  myobj = gTTS(text=text, lang=get_key(final_language), slow=False)
100
+ if os.path.exists(f"audio_resume_traduire{cnt}.wav"):
101
+ os.remove(f"audio_resume_traduire{cnt}.wav")
102
+ else:
103
+ print("Impossible de supprimer le fichier car il n'existe pas")
104
  myobj.save(f"audio_resume_traduire{cnt}.wav")
105
  return f"audio_resume_traduire{cnt}.wav", text_translate
106
  else:
 
108
  text_translate = text_translate[0]['summary_text']
109
  text = translator.translate(text_translate)
110
  myobj = gTTS(text=text_translate, lang=text.src, slow=False)
111
+ if os.path.exists(f"audio_resume{cnt}.wav"):
112
+ os.remove(f"audio_resume{cnt}.wav")
113
+ else:
114
+ print("Impossible de supprimer le fichier car il n'existe pas")
115
  myobj.save(f"audio_resume{cnt}.wav")
116
  return f"audio_resume{cnt}.wav", text_translate
117