JairoCesar commited on
Commit
43c6bb4
·
verified ·
1 Parent(s): ee03342

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py CHANGED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+ from pptx import Presentation
4
+ from pptx.util import Inches, Pt
5
+ import os
6
+
7
+ def generate_presentation_content(topic, model, tokenizer):
8
+ prompt = f"Crea una presentación de PowerPoint sobre el tema: {topic}. Incluye 5 diapositivas con títulos y contenido."
9
+ input_ids = tokenizer.encode(prompt, return_tensors="pt")
10
+
11
+ output = model.generate(input_ids, max_length=500, num_return_sequences=1, temperature=0.7)
12
+ generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
13
+
14
+ slides = generated_text.split("\n\n")
15
+ return slides[:5] # Limitar a 5 diapositivas
16
+
17
+ def create_powerpoint(slides, output_file):
18
+ prs = Presentation()
19
+
20
+ for slide_content in slides:
21
+ slide = prs.slides.add_slide(prs.slide_layouts[1])
22
+
23
+ lines = slide_content.split("\n")
24
+ title = lines[0]
25
+ content = "\n".join(lines[1:])
26
+
27
+ title_shape = slide.shapes.title
28
+ content_shape = slide.placeholders[1]
29
+
30
+ title_shape.text = title
31
+ content_shape.text = content
32
+
33
+ prs.save(output_file)
34
+
35
+ def main():
36
+ print("Bienvenido al generador de presentaciones PowerPoint con IA")
37
+ topic = input("Por favor, ingrese el tema de la presentación: ")
38
+
39
+ model_name = "meta-llama/Llama-2-7b-chat-hf"
40
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
41
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
42
+
43
+ print("Generando contenido de la presentación...")
44
+ slides = generate_presentation_content(topic, model, tokenizer)
45
+
46
+ output_file = f"{topic.replace(' ', '_')}_presentacion.pptx"
47
+ print(f"Creando archivo PowerPoint: {output_file}")
48
+ create_powerpoint(slides, output_file)
49
+
50
+ print(f"Presentación generada y guardada como {output_file}")
51
+
52
+ if __name__ == "__main__":
53
+ main()