Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
#Separation Du Code
|
| 4 |
#Correction Sortie Logs
|
| 5 |
|
|
|
|
| 6 |
import os
|
| 7 |
import gradio as gr
|
| 8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
@@ -35,15 +36,6 @@ class ExecutionTimer:
|
|
| 35 |
self.start_time = None
|
| 36 |
return self.last_duration
|
| 37 |
|
| 38 |
-
def get_status(self):
|
| 39 |
-
if self.start_time is not None:
|
| 40 |
-
current = self.get_elapsed()
|
| 41 |
-
last = f" (précédent: {self.last_duration:.2f}s)" if self.last_duration else ""
|
| 42 |
-
return f"En cours... {current:.2f}s{last}"
|
| 43 |
-
elif self.last_duration:
|
| 44 |
-
return f"Terminé en {self.last_duration:.2f}s"
|
| 45 |
-
return "En attente..."
|
| 46 |
-
|
| 47 |
def generate_text(model_path, prompt, temperature=0.7, max_tokens=2048):
|
| 48 |
try:
|
| 49 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
|
@@ -92,7 +84,7 @@ def generate_skeleton(model_name, text, temperature, max_tokens):
|
|
| 92 |
full_prompt = PREPROMPT + "\n\n" + text
|
| 93 |
generated_content = generate_text(model_path, full_prompt, temperature, max_tokens)
|
| 94 |
|
| 95 |
-
status =
|
| 96 |
timer.stop()
|
| 97 |
|
| 98 |
return status, generated_content, gr.update(visible=True)
|
|
@@ -126,12 +118,22 @@ def create_presentation_file(generated_content):
|
|
| 126 |
# Timer global pour le suivi du temps
|
| 127 |
timer = ExecutionTimer()
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
# Interface Gradio
|
| 130 |
with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
| 131 |
gr.Markdown(
|
| 132 |
"""
|
| 133 |
# Générateur de Présentations PowerPoint IA
|
| 134 |
-
|
| 135 |
Créez des présentations professionnelles automatiquement avec l'aide de l'IA.
|
| 136 |
"""
|
| 137 |
)
|
|
@@ -174,7 +176,7 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
|
| 174 |
status_output = gr.Textbox(
|
| 175 |
label="Statut",
|
| 176 |
lines=10,
|
| 177 |
-
value=
|
| 178 |
)
|
| 179 |
generated_content = gr.Textbox(
|
| 180 |
label="Contenu généré",
|
|
@@ -188,8 +190,8 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
|
| 188 |
)
|
| 189 |
|
| 190 |
def update_status():
|
| 191 |
-
"""Met à jour le statut avec
|
| 192 |
-
return
|
| 193 |
|
| 194 |
generate_skeleton_btn.click(
|
| 195 |
fn=generate_skeleton,
|
|
@@ -223,3 +225,5 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
|
| 223 |
|
| 224 |
if __name__ == "__main__":
|
| 225 |
demo.launch()
|
|
|
|
|
|
|
|
|
| 3 |
#Separation Du Code
|
| 4 |
#Correction Sortie Logs
|
| 5 |
|
| 6 |
+
|
| 7 |
import os
|
| 8 |
import gradio as gr
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 36 |
self.start_time = None
|
| 37 |
return self.last_duration
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def generate_text(model_path, prompt, temperature=0.7, max_tokens=2048):
|
| 40 |
try:
|
| 41 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
|
|
|
| 84 |
full_prompt = PREPROMPT + "\n\n" + text
|
| 85 |
generated_content = generate_text(model_path, full_prompt, temperature, max_tokens)
|
| 86 |
|
| 87 |
+
status = "Génération terminée."
|
| 88 |
timer.stop()
|
| 89 |
|
| 90 |
return status, generated_content, gr.update(visible=True)
|
|
|
|
| 118 |
# Timer global pour le suivi du temps
|
| 119 |
timer = ExecutionTimer()
|
| 120 |
|
| 121 |
+
# Variable partagée pour stocker les logs
|
| 122 |
+
logs = []
|
| 123 |
+
|
| 124 |
+
def log_message(message):
|
| 125 |
+
"""Ajoute un message aux logs"""
|
| 126 |
+
logs.append(message)
|
| 127 |
+
|
| 128 |
+
def get_logs():
|
| 129 |
+
"""Récupère tous les logs"""
|
| 130 |
+
return "\n".join(logs)
|
| 131 |
+
|
| 132 |
# Interface Gradio
|
| 133 |
with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
| 134 |
gr.Markdown(
|
| 135 |
"""
|
| 136 |
# Générateur de Présentations PowerPoint IA
|
|
|
|
| 137 |
Créez des présentations professionnelles automatiquement avec l'aide de l'IA.
|
| 138 |
"""
|
| 139 |
)
|
|
|
|
| 176 |
status_output = gr.Textbox(
|
| 177 |
label="Statut",
|
| 178 |
lines=10,
|
| 179 |
+
value="En attente..."
|
| 180 |
)
|
| 181 |
generated_content = gr.Textbox(
|
| 182 |
label="Contenu généré",
|
|
|
|
| 190 |
)
|
| 191 |
|
| 192 |
def update_status():
|
| 193 |
+
"""Met à jour le statut avec les logs"""
|
| 194 |
+
return f"Logs:\n{get_logs()}"
|
| 195 |
|
| 196 |
generate_skeleton_btn.click(
|
| 197 |
fn=generate_skeleton,
|
|
|
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|
| 227 |
demo.launch()
|
| 228 |
+
|
| 229 |
+
|