Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
#https://huggingface.co/spaces/MisterAI/GenDoc_05
|
2 |
-
#143
|
3 |
-
|
4 |
import os
|
5 |
import gradio as gr
|
6 |
from huggingface_hub import hf_hub_download, login
|
@@ -54,12 +51,21 @@ class PresentationGenerator:
|
|
54 |
def load_text_model(self, model_name):
|
55 |
"""Charge le modèle de génération de texte"""
|
56 |
model_id = TEXT_MODELS[model_name]
|
|
|
|
|
|
|
57 |
if model_id.endswith('.gguf'):
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
self.text_model = Llama(
|
64 |
model_path=model_path,
|
65 |
n_ctx=4096,
|
@@ -79,6 +85,7 @@ class PresentationGenerator:
|
|
79 |
|
80 |
def generate_text(self, prompt, temperature=0.7, max_tokens=4096):
|
81 |
"""Génère le texte de la présentation"""
|
|
|
82 |
if isinstance(self.text_model, Llama):
|
83 |
response = self.text_model(
|
84 |
prompt,
|
@@ -86,8 +93,7 @@ class PresentationGenerator:
|
|
86 |
temperature=temperature,
|
87 |
echo=False
|
88 |
)
|
89 |
-
|
90 |
-
return response['choices'][0]['text']
|
91 |
else:
|
92 |
inputs = self.text_tokenizer.apply_chat_template(
|
93 |
[{"role": "user", "content": prompt}],
|
@@ -100,8 +106,9 @@ class PresentationGenerator:
|
|
100 |
temperature=temperature
|
101 |
)
|
102 |
generated_text = self.text_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
103 |
-
|
104 |
-
|
|
|
105 |
|
106 |
def parse_presentation_content(self, content):
|
107 |
"""Parse le contenu généré en sections pour les diapositives"""
|
@@ -184,7 +191,7 @@ def generate_presentation_with_progress(text, text_model_name, temperature, max_
|
|
184 |
status = f"Présentation générée avec succès en {execution_time:.2f} secondes!"
|
185 |
|
186 |
# Retourne le statut, le contenu généré et le fichier
|
187 |
-
return status, generated_content,
|
188 |
|
189 |
except Exception as e:
|
190 |
print(f"Erreur lors de la génération: {str(e)}")
|
@@ -322,5 +329,3 @@ with gr.Blocks(theme=gr.themes.Default(), css=css) as demo:
|
|
322 |
|
323 |
if __name__ == "__main__":
|
324 |
demo.launch()
|
325 |
-
|
326 |
-
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import hf_hub_download, login
|
|
|
51 |
def load_text_model(self, model_name):
|
52 |
"""Charge le modèle de génération de texte"""
|
53 |
model_id = TEXT_MODELS[model_name]
|
54 |
+
model_path = None
|
55 |
+
|
56 |
+
# Vérifiez si le modèle est déjà téléchargé localement
|
57 |
if model_id.endswith('.gguf'):
|
58 |
+
model_filename = model_id.split('/')[-1]
|
59 |
+
local_path = f"./models/{model_filename}"
|
60 |
+
if os.path.exists(local_path):
|
61 |
+
model_path = local_path
|
62 |
+
else:
|
63 |
+
model_path = hf_hub_download(
|
64 |
+
repo_id=model_id.split('/')[0] + '/' + model_id.split('/')[1],
|
65 |
+
filename=model_filename,
|
66 |
+
token=self.token,
|
67 |
+
cache_dir="./models"
|
68 |
+
)
|
69 |
self.text_model = Llama(
|
70 |
model_path=model_path,
|
71 |
n_ctx=4096,
|
|
|
85 |
|
86 |
def generate_text(self, prompt, temperature=0.7, max_tokens=4096):
|
87 |
"""Génère le texte de la présentation"""
|
88 |
+
start_time = time.time()
|
89 |
if isinstance(self.text_model, Llama):
|
90 |
response = self.text_model(
|
91 |
prompt,
|
|
|
93 |
temperature=temperature,
|
94 |
echo=False
|
95 |
)
|
96 |
+
generated_text = response['choices'][0]['text']
|
|
|
97 |
else:
|
98 |
inputs = self.text_tokenizer.apply_chat_template(
|
99 |
[{"role": "user", "content": prompt}],
|
|
|
106 |
temperature=temperature
|
107 |
)
|
108 |
generated_text = self.text_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
109 |
+
|
110 |
+
print(f"Texte généré en {time.time() - start_time:.2f} secondes")
|
111 |
+
return generated_text
|
112 |
|
113 |
def parse_presentation_content(self, content):
|
114 |
"""Parse le contenu généré en sections pour les diapositives"""
|
|
|
191 |
status = f"Présentation générée avec succès en {execution_time:.2f} secondes!"
|
192 |
|
193 |
# Retourne le statut, le contenu généré et le fichier
|
194 |
+
return status, generated_content, output_path
|
195 |
|
196 |
except Exception as e:
|
197 |
print(f"Erreur lors de la génération: {str(e)}")
|
|
|
329 |
|
330 |
if __name__ == "__main__":
|
331 |
demo.launch()
|
|
|
|