File size: 3,853 Bytes
f507e2f
 
 
 
 
e6873c3
9de28b9
 
1a5f0d1
ca3ed85
39663ce
8577755
 
 
 
 
 
 
 
f507e2f
 
ca3ed85
 
 
 
 
 
299811a
4cdd93c
170b9b5
a3b82fb
70fb463
 
 
 
 
 
 
 
170b9b5
4cdd93c
c8dfba0
879a2f6
 
ca3ed85
 
 
299811a
 
f507e2f
ca3ed85
 
 
 
 
 
 
 
f507e2f
8577755
 
 
f507e2f
8577755
f507e2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import gradio as gr
from transformers import pipeline
from pptx import Presentation
from pptx.util import Inches
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextIteratorStreamer
#from llama_cpp import Llama LLMCppModel
from llama_cpp import Llama
from huggingface_hub import hf_hub_download


# Préprompt pour donner des instructions au modèle
PREPROMPT = """Vous êtes un assistant IA chargé de générer une présentation PowerPoint à partir d'un texte fourni par un utilisateur. Voici les instructions à suivre :
- Analysez attentivement le texte pour en comprendre les idées principales et la structure.
- Générez des titres et sous-titres pertinents pour chaque diapositive.
- Résumez les points clés sous forme de listes à puces.
- Ajoutez du texte explicatif pour chaque diapositive afin de compléter le contenu.
- Assurez-vous que la présentation soit cohérente, logique et visuellement attractive.
Voici le texte à transformer en présentation :"""

# Chargement du modèle IA depuis Hugging Face
#text_to_presentation = pipeline("text-generation", model="MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF")
#tokenizer = AutoTokenizer.from_pretrained("MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF")


# Chargement du modèle IA depuis Hugging Face
#from llama_cpp import LLMCppModel
#model_path = "MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF"
#model_path = "https://huggingface.co/MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF/tree/main/mistralai_Mistral-Small-24B-Base-2501-Q8_0.gguf"
#model_path = "https://huggingface.co/MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF/resolve/main/mistralai_Mistral-Small-24B-Base-2501-Q8_0.gguf"
#model_path = "https://huggingface.co/MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF/mistralai_Mistral-Small-24B-Base-2501-Q8_0.gguf"
#model_path = "MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF/mistralai_Mistral-Small-24B-Base-2501-Q8_0.gguf"
# Téléchargement du modèle depuis Hugging Face
model_file = "mistralai_Mistral-Small-24B-Base-2501-Q8_0.gguf"
model_path = hf_hub_download(
    repo_id="MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF",
    filename=model_file,
    repo_type="model"
)


#text_to_presentation = LLMCppModel(model_path)
#text_to_presentation = model_path
text_to_presentation = Llama(model_path, verbose=True)

# Chargement du tokenizer depuis Hugging Face
#from transformers import AutoTokenizer
#tokenizer = AutoTokenizer.from_pretrained("MisterAI/Bartowski_MistralAI_Mistral-Small-24B-Base-2501-GGUF")
tokenizer = AutoTokenizer.from_pretrained(model_path)









def generate_presentation(text):
    # Ajout du préprompt au texte de l'utilisateur
    full_prompt = PREPROMPT + "\n\n" + text

    # Analyse du texte avec le modèle IA
    presentation_content = text_to_presentation(full_prompt, max_length=1500, num_return_sequences=1)[0]["generated_text"]

    # Génération de la présentation PowerPoint
    prs = Presentation()
    slide = prs.slides.add_slide(prs.slide_layouts[0])
    title = slide.shapes.title
    title.text = "Présentation générée"
    body = slide.placeholders[1].text_frame
    body.text = presentation_content

    # Enregistrement de la présentation
    prs.save("presentation.pptx")

    # Retourner le lien de téléchargement
    return "Votre présentation est prête ! Vous pouvez la télécharger ici : " + os.path.abspath("presentation.pptx")

# Interface Gradio
demo = gr.Interface(
    fn=generate_presentation,
    inputs="text",
    outputs="text",
    title="Générateur de présentations",
    description="Entrez du texte et obtenez une présentation PowerPoint générée automatiquement."
)

if __name__ == "__main__":
    demo.launch()