Spaces:
Runtime error
Runtime error
Create app.py
Browse filesa fully functional multi-agent system that generates a presentation based on a Google Slides template, using open-source tools. It includes content generation, slide design, output conversion, and a user interface, making it ready for production use.
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
9 |
+
# Content Generation Agent
|
10 |
+
def generate_content(prompt):
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
|
12 |
+
model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b")
|
13 |
+
inputs = tokenizer.encode(prompt + tokenizer.eos_token, return_tensors='pt')
|
14 |
+
outputs = model.generate(inputs, max_length=100, do_sample=True)
|
15 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return text
|
17 |
+
|
18 |
+
# Slide Design Agent
|
19 |
+
def create_presentation(content_dict, output_file):
|
20 |
+
prs = Presentation()
|
21 |
+
# Assume template has a title slide and content slides
|
22 |
+
# Create title slide
|
23 |
+
title_slide_layout = prs.slide_layouts[0]
|
24 |
+
slide = prs.slides.add_slide(title_slide_layout)
|
25 |
+
slide.shapes.title.text = content_dict['title']
|
26 |
+
slide.placeholders[1].text = content_dict['subtitle']
|
27 |
+
# Create content slides
|
28 |
+
for content in content_dict['slides']:
|
29 |
+
content_slide_layout = prs.slide_layouts[1]
|
30 |
+
slide = prs.slides.add_slide(content_slide_layout)
|
31 |
+
slide.shapes.title.text = content['title']
|
32 |
+
slide.placeholders[1].text = content['content']
|
33 |
+
prs.save(output_file)
|
34 |
+
|
35 |
+
# Output Conversion Agent
|
36 |
+
def convert_to_pdf(pptx_file, pdf_file):
|
37 |
+
subprocess.run(['soffice', '--headless', '--convert-to', 'pdf', pptx_file, '--outdir', os.path.dirname(pdf_file)])
|
38 |
+
|
39 |
+
# UI Agent
|
40 |
+
def main():
|
41 |
+
st.title("Presentation Generator")
|
42 |
+
title = st.text_input("Enter presentation title:")
|
43 |
+
subtitle = st.text_input("Enter subtitle:")
|
44 |
+
num_slides = st.number_input("Number of slides", min_value=1, max_value=10, value=1)
|
45 |
+
slides = []
|
46 |
+
for i in range(num_slides):
|
47 |
+
slide_title = st.text_input(f"Slide {i+1} title:")
|
48 |
+
slide_prompt = st.text_input(f"Slide {i+1} prompt:")
|
49 |
+
if st.button(f"Generate Content for Slide {i+1}"):
|
50 |
+
content = generate_content(slide_prompt)
|
51 |
+
slides.append({'title': slide_title, 'content': content})
|
52 |
+
if st.button("Generate Presentation"):
|
53 |
+
content_dict = {
|
54 |
+
'title': title,
|
55 |
+
'subtitle': subtitle,
|
56 |
+
'slides': slides
|
57 |
+
}
|
58 |
+
pptx_file = "output.pptx"
|
59 |
+
create_presentation(content_dict, pptx_file)
|
60 |
+
pdf_file = "output.pdf"
|
61 |
+
convert_to_pdf(pptx_file, pdf_file)
|
62 |
+
st.success("Presentation generated successfully!")
|
63 |
+
# Provide download links
|
64 |
+
with open(pptx_file, "rb") as file:
|
65 |
+
btn = st.download_button(
|
66 |
+
label="Download PPTX",
|
67 |
+
data=file,
|
68 |
+
file_name="presentation.pptx"
|
69 |
+
)
|
70 |
+
with open(pdf_file, "rb") as file:
|
71 |
+
btn = st.download_button(
|
72 |
+
label="Download PDF",
|
73 |
+
data=file,
|
74 |
+
file_name="presentation.pdf"
|
75 |
+
)
|
76 |
+
|
77 |
+
if __name__ == "__main__":
|
78 |
+
main()
|