antiquesordo commited on
Commit
67a7445
·
verified ·
1 Parent(s): 4f8238c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -59
app.py CHANGED
@@ -1,15 +1,11 @@
1
- # Import necessary libraries
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  from pptx import Presentation
4
  from pptx.util import Inches
5
- import streamlit as st
6
  import subprocess
7
  import os
8
- try:
9
- from transformers import AutoTokenizer, AutoModelForCausalLM
10
- except ImportError:
11
- print("Transformers library is not installed. Please install it using pip install transformers.")
12
- # Content Generation Agent
13
  def generate_content(prompt):
14
  tokenizer = AutoTokenizer.from_pretrained("gpt2")
15
  model = AutoModelForCausalLM.from_pretrained("gpt2")
@@ -18,64 +14,49 @@ def generate_content(prompt):
18
  text = tokenizer.decode(outputs[0], skip_special_tokens=True)
19
  return text
20
 
21
- # Slide Design Agent
22
  def create_presentation(content_dict, output_file):
23
  prs = Presentation()
24
- # Assume template has a title slide and content slides
25
- # Create title slide
26
- title_slide_layout = prs.slide_layouts[0]
27
- slide = prs.slides.add_slide(title_slide_layout)
28
- slide.shapes.title.text = content_dict['title']
29
- slide.placeholders[1].text = content_dict['subtitle']
30
- # Create content slides
31
- for content in content_dict['slides']:
32
- content_slide_layout = prs.slide_layouts[1]
33
- slide = prs.slides.add_slide(content_slide_layout)
34
- slide.shapes.title.text = content['title']
35
- slide.placeholders[1].text = content['content']
36
  prs.save(output_file)
37
 
38
- # Output Conversion Agent
39
  def convert_to_pdf(pptx_file, pdf_file):
40
  subprocess.run(['soffice', '--headless', '--convert-to', 'pdf', pptx_file, '--outdir', os.path.dirname(pdf_file)])
41
 
42
- # UI Agent
43
- def main():
44
- st.title("Presentation Generator")
45
- title = st.text_input("Enter presentation title:")
46
- subtitle = st.text_input("Enter subtitle:")
47
- num_slides = st.number_input("Number of slides", min_value=1, max_value=10, value=1)
48
  slides = []
49
- for i in range(num_slides):
50
- slide_title = st.text_input(f"Slide {i+1} title:")
51
- slide_prompt = st.text_input(f"Slide {i+1} prompt:")
52
- if st.button(f"Generate Content for Slide {i+1}"):
53
- content = generate_content(slide_prompt)
54
- slides.append({'title': slide_title, 'content': content})
55
- if st.button("Generate Presentation"):
56
- content_dict = {
57
- 'title': title,
58
- 'subtitle': subtitle,
59
- 'slides': slides
60
- }
61
- pptx_file = "output.pptx"
62
- create_presentation(content_dict, pptx_file)
63
- pdf_file = "output.pdf"
64
- convert_to_pdf(pptx_file, pdf_file)
65
- st.success("Presentation generated successfully!")
66
- # Provide download links
67
- with open(pptx_file, "rb") as file:
68
- btn = st.download_button(
69
- label="Download PPTX",
70
- data=file,
71
- file_name="presentation.pptx"
72
- )
73
- with open(pdf_file, "rb") as file:
74
- btn = st.download_button(
75
- label="Download PDF",
76
- data=file,
77
- file_name="presentation.pdf"
78
- )
79
 
80
- if __name__ == "__main__":
81
- main()
 
1
+ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  from pptx import Presentation
4
  from pptx.util import Inches
 
5
  import subprocess
6
  import os
7
+
8
+ # Content Generation Function
 
 
 
9
  def generate_content(prompt):
10
  tokenizer = AutoTokenizer.from_pretrained("gpt2")
11
  model = AutoModelForCausalLM.from_pretrained("gpt2")
 
14
  text = tokenizer.decode(outputs[0], skip_special_tokens=True)
15
  return text
16
 
17
+ # Slide Design Function
18
  def create_presentation(content_dict, output_file):
19
  prs = Presentation()
20
+ # Create slides based on content_dict
21
+ # ...
 
 
 
 
 
 
 
 
 
 
22
  prs.save(output_file)
23
 
24
+ # Output Conversion Function
25
  def convert_to_pdf(pptx_file, pdf_file):
26
  subprocess.run(['soffice', '--headless', '--convert-to', 'pdf', pptx_file, '--outdir', os.path.dirname(pdf_file)])
27
 
28
+ # Main Function
29
+ def main(title, subtitle, num_slides, slide_prompts):
 
 
 
 
30
  slides = []
31
+ for prompt in slide_prompts:
32
+ content = generate_content(prompt)
33
+ slides.append({'title': content, 'content': content})
34
+ content_dict = {
35
+ 'title': title,
36
+ 'subtitle': subtitle,
37
+ 'slides': slides
38
+ }
39
+ pptx_file = "output.pptx"
40
+ create_presentation(content_dict, pptx_file)
41
+ pdf_file = "output.pdf"
42
+ convert_to_pdf(pptx_file, pdf_file)
43
+ return pptx_file, pdf_file
44
+
45
+ # Gradio Interface
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown("# Presentation Generator")
48
+ title = gr.Textbox(label="Presentation Title")
49
+ subtitle = gr.Textbox(label="Subtitle")
50
+ num_slides = gr.Number(label="Number of Slides", value=1)
51
+ slide_prompts = gr.Textbox(label="Slide Prompts (one per line)", lines=5)
52
+ generate_button = gr.Button("Generate Presentation")
53
+ output_pptx = gr.File(label="Download PPTX")
54
+ output_pdf = gr.File(label="Download PDF")
55
+
56
+ generate_button.click(
57
+ main,
58
+ inputs=[title, subtitle, num_slides, slide_prompts],
59
+ outputs=[output_pptx, output_pdf]
60
+ )
61
 
62
+ demo.launch()