JairoCesar commited on
Commit
098f563
·
verified ·
1 Parent(s): 906d862

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -15
app.py CHANGED
@@ -1,8 +1,17 @@
 
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."
@@ -14,7 +23,7 @@ def generate_presentation_content(topic, model, tokenizer):
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:
@@ -30,24 +39,40 @@ def create_powerpoint(slides, output_file):
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()
 
1
+ import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
  from pptx import Presentation
5
  from pptx.util import Inches, Pt
6
  import os
7
+ import io
8
+
9
+ @st.cache_resource
10
+ def load_model():
11
+ model_name = "meta-llama/Llama-2-7b-chat-hf"
12
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
13
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
14
+ return tokenizer, model
15
 
16
  def generate_presentation_content(topic, model, tokenizer):
17
  prompt = f"Crea una presentación de PowerPoint sobre el tema: {topic}. Incluye 5 diapositivas con títulos y contenido."
 
23
  slides = generated_text.split("\n\n")
24
  return slides[:5] # Limitar a 5 diapositivas
25
 
26
+ def create_powerpoint(slides):
27
  prs = Presentation()
28
 
29
  for slide_content in slides:
 
39
  title_shape.text = title
40
  content_shape.text = content
41
 
42
+ # Guardar la presentación en un buffer de bytes
43
+ pptx_buffer = io.BytesIO()
44
+ prs.save(pptx_buffer)
45
+ pptx_buffer.seek(0)
46
+
47
+ return pptx_buffer
48
 
49
  def main():
50
+ st.title("Generador de presentaciones PowerPoint con IA")
 
 
 
 
 
 
 
 
51
 
52
+ topic = st.text_input("Por favor, ingrese el tema de la presentación:")
 
 
53
 
54
+ if st.button("Generar Presentación"):
55
+ if topic:
56
+ with st.spinner("Cargando modelo..."):
57
+ tokenizer, model = load_model()
58
+
59
+ with st.spinner("Generando contenido de la presentación..."):
60
+ slides = generate_presentation_content(topic, model, tokenizer)
61
+
62
+ with st.spinner("Creando archivo PowerPoint..."):
63
+ pptx_buffer = create_powerpoint(slides)
64
+
65
+ st.success("Presentación generada con éxito!")
66
+
67
+ # Ofrecer la descarga del archivo
68
+ st.download_button(
69
+ label="Descargar Presentación",
70
+ data=pptx_buffer,
71
+ file_name=f"{topic.replace(' ', '_')}_presentacion.pptx",
72
+ mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
73
+ )
74
+ else:
75
+ st.warning("Por favor, ingrese un tema para la presentación.")
76
 
77
  if __name__ == "__main__":
78
  main()