| | 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 |
| | from huggingface_hub import hf_hub_download |
| |
|
| |
|
| | |
| | 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 :""" |
| |
|
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | 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 = Llama(model_path, verbose=True) |
| |
|
| | |
| | |
| | |
| | tokenizer = AutoTokenizer.from_pretrained(model_path) |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | def generate_presentation(text): |
| | |
| | full_prompt = PREPROMPT + "\n\n" + text |
| |
|
| | |
| | presentation_content = text_to_presentation(full_prompt, max_length=1500, num_return_sequences=1)[0]["generated_text"] |
| |
|
| | |
| | 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 |
| |
|
| | |
| | prs.save("presentation.pptx") |
| |
|
| | |
| | return "Votre présentation est prête ! Vous pouvez la télécharger ici : " + os.path.abspath("presentation.pptx") |
| |
|
| | |
| | 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() |
| |
|