Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
#https://huggingface.co/spaces/MisterAI/GenDoc_05
|
| 2 |
-
#
|
| 3 |
-
|
| 4 |
|
| 5 |
|
| 6 |
import os
|
|
@@ -15,6 +14,7 @@ import time
|
|
| 15 |
|
| 16 |
# Configuration des modèles et PREPROMPT
|
| 17 |
TEXT_MODELS = {
|
|
|
|
| 18 |
"Mistral Nemo 2407 (GGUF)": "MisterAI/Bartowski_MistralAI_Mistral-Nemo-Instruct-2407-IQ4_XS.gguf",
|
| 19 |
"Mixtral 8x7B": "mistralai/Mixtral-8x7B-v0.1",
|
| 20 |
"Lucie 7B": "OpenLLM-France/Lucie-7B"
|
|
@@ -163,8 +163,8 @@ class PresentationGenerator:
|
|
| 163 |
|
| 164 |
return prs
|
| 165 |
|
| 166 |
-
def
|
| 167 |
-
"""
|
| 168 |
try:
|
| 169 |
start_time = time.time()
|
| 170 |
generator = PresentationGenerator()
|
|
@@ -178,8 +178,23 @@ def generate_presentation_with_progress(text, text_model_name, temperature, max_
|
|
| 178 |
full_prompt = PREPROMPT + "\n\n" + text
|
| 179 |
generated_content = generator.generate_text(full_prompt, temperature, max_tokens)
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
# Création de la présentation
|
| 182 |
-
yield "Création de la présentation PowerPoint...",
|
| 183 |
slides = generator.parse_presentation_content(generated_content)
|
| 184 |
prs = generator.create_presentation(slides)
|
| 185 |
|
|
@@ -191,17 +206,13 @@ def generate_presentation_with_progress(text, text_model_name, temperature, max_
|
|
| 191 |
if not os.path.exists(output_path):
|
| 192 |
raise FileNotFoundError(f"Le fichier {output_path} n'a pas été créé correctement")
|
| 193 |
|
| 194 |
-
|
| 195 |
-
status = f"Présentation générée avec succès en {execution_time:.2f} secondes!"
|
| 196 |
-
|
| 197 |
-
# Retourne le statut, le contenu généré et le fichier
|
| 198 |
-
return status, generated_content, output_path
|
| 199 |
|
| 200 |
except Exception as e:
|
| 201 |
-
print(f"Erreur lors de la
|
| 202 |
-
return
|
| 203 |
|
| 204 |
-
with gr.Blocks() as demo:
|
| 205 |
gr.Markdown(
|
| 206 |
"""
|
| 207 |
# Générateur de Présentations PowerPoint IA
|
|
@@ -241,7 +252,7 @@ with gr.Blocks() as demo:
|
|
| 241 |
)
|
| 242 |
|
| 243 |
with gr.Row():
|
| 244 |
-
|
| 245 |
|
| 246 |
with gr.Row():
|
| 247 |
with gr.Column():
|
|
@@ -254,12 +265,14 @@ with gr.Blocks() as demo:
|
|
| 254 |
lines=10,
|
| 255 |
show_copy_button=True
|
| 256 |
)
|
|
|
|
| 257 |
output_file = gr.File(
|
| 258 |
label="Présentation PowerPoint"
|
| 259 |
)
|
|
|
|
| 260 |
|
| 261 |
-
|
| 262 |
-
fn=
|
| 263 |
inputs=[
|
| 264 |
input_text,
|
| 265 |
text_model_choice,
|
|
@@ -269,7 +282,16 @@ with gr.Blocks() as demo:
|
|
| 269 |
outputs=[
|
| 270 |
status_output,
|
| 271 |
generated_content,
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
]
|
| 274 |
)
|
| 275 |
|
|
|
|
| 1 |
#https://huggingface.co/spaces/MisterAI/GenDoc_05
|
| 2 |
+
#app.py_143
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 14 |
|
| 15 |
# Configuration des modèles et PREPROMPT
|
| 16 |
TEXT_MODELS = {
|
| 17 |
+
"Utter-Project_EuroLLM-1.7B": "utter-project/EuroLLM-1.7B",
|
| 18 |
"Mistral Nemo 2407 (GGUF)": "MisterAI/Bartowski_MistralAI_Mistral-Nemo-Instruct-2407-IQ4_XS.gguf",
|
| 19 |
"Mixtral 8x7B": "mistralai/Mixtral-8x7B-v0.1",
|
| 20 |
"Lucie 7B": "OpenLLM-France/Lucie-7B"
|
|
|
|
| 163 |
|
| 164 |
return prs
|
| 165 |
|
| 166 |
+
def generate_skeleton(text, text_model_name, temperature, max_tokens):
|
| 167 |
+
"""Génère le squelette de la présentation"""
|
| 168 |
try:
|
| 169 |
start_time = time.time()
|
| 170 |
generator = PresentationGenerator()
|
|
|
|
| 178 |
full_prompt = PREPROMPT + "\n\n" + text
|
| 179 |
generated_content = generator.generate_text(full_prompt, temperature, max_tokens)
|
| 180 |
|
| 181 |
+
execution_time = time.time() - start_time
|
| 182 |
+
status = f"Squelette généré avec succès en {execution_time:.2f} secondes!"
|
| 183 |
+
|
| 184 |
+
# Retourne le statut et le contenu généré
|
| 185 |
+
return status, generated_content, None
|
| 186 |
+
|
| 187 |
+
except Exception as e:
|
| 188 |
+
print(f"Erreur lors de la génération: {str(e)}")
|
| 189 |
+
return f"Erreur: {str(e)}", None, None
|
| 190 |
+
|
| 191 |
+
def create_presentation_file(generated_content):
|
| 192 |
+
"""Crée le fichier PowerPoint à partir du contenu généré"""
|
| 193 |
+
try:
|
| 194 |
+
generator = PresentationGenerator()
|
| 195 |
+
|
| 196 |
# Création de la présentation
|
| 197 |
+
yield "Création de la présentation PowerPoint...", None
|
| 198 |
slides = generator.parse_presentation_content(generated_content)
|
| 199 |
prs = generator.create_presentation(slides)
|
| 200 |
|
|
|
|
| 206 |
if not os.path.exists(output_path):
|
| 207 |
raise FileNotFoundError(f"Le fichier {output_path} n'a pas été créé correctement")
|
| 208 |
|
| 209 |
+
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
except Exception as e:
|
| 212 |
+
print(f"Erreur lors de la création du fichier: {str(e)}")
|
| 213 |
+
return None
|
| 214 |
|
| 215 |
+
with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
| 216 |
gr.Markdown(
|
| 217 |
"""
|
| 218 |
# Générateur de Présentations PowerPoint IA
|
|
|
|
| 252 |
)
|
| 253 |
|
| 254 |
with gr.Row():
|
| 255 |
+
generate_skeleton_btn = gr.Button("Générer le Squelette de la Présentation", variant="primary")
|
| 256 |
|
| 257 |
with gr.Row():
|
| 258 |
with gr.Column():
|
|
|
|
| 265 |
lines=10,
|
| 266 |
show_copy_button=True
|
| 267 |
)
|
| 268 |
+
create_presentation_btn = gr.Button("Créer Présentation")
|
| 269 |
output_file = gr.File(
|
| 270 |
label="Présentation PowerPoint"
|
| 271 |
)
|
| 272 |
+
progress_bar = gr.Progress(track_tqdm=True)
|
| 273 |
|
| 274 |
+
generate_skeleton_btn.click(
|
| 275 |
+
fn=generate_skeleton,
|
| 276 |
inputs=[
|
| 277 |
input_text,
|
| 278 |
text_model_choice,
|
|
|
|
| 282 |
outputs=[
|
| 283 |
status_output,
|
| 284 |
generated_content,
|
| 285 |
+
create_presentation_btn
|
| 286 |
+
]
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
create_presentation_btn.click(
|
| 290 |
+
fn=create_presentation_file,
|
| 291 |
+
inputs=generated_content,
|
| 292 |
+
outputs=[
|
| 293 |
+
output_file,
|
| 294 |
+
progress_bar
|
| 295 |
]
|
| 296 |
)
|
| 297 |
|