# Import necessary libraries from transformers import AutoTokenizer, AutoModelForCausalLM from pptx import Presentation from pptx.util import Inches import streamlit as st import subprocess import os # Content Generation Agent def generate_content(prompt): tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b") model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b") inputs = tokenizer.encode(prompt + tokenizer.eos_token, return_tensors='pt') outputs = model.generate(inputs, max_length=100, do_sample=True) text = tokenizer.decode(outputs[0], skip_special_tokens=True) return text # Slide Design Agent def create_presentation(content_dict, output_file): prs = Presentation() # Assume template has a title slide and content slides # Create title slide title_slide_layout = prs.slide_layouts[0] slide = prs.slides.add_slide(title_slide_layout) slide.shapes.title.text = content_dict['title'] slide.placeholders[1].text = content_dict['subtitle'] # Create content slides for content in content_dict['slides']: content_slide_layout = prs.slide_layouts[1] slide = prs.slides.add_slide(content_slide_layout) slide.shapes.title.text = content['title'] slide.placeholders[1].text = content['content'] prs.save(output_file) # Output Conversion Agent def convert_to_pdf(pptx_file, pdf_file): subprocess.run(['soffice', '--headless', '--convert-to', 'pdf', pptx_file, '--outdir', os.path.dirname(pdf_file)]) # UI Agent def main(): st.title("Presentation Generator") title = st.text_input("Enter presentation title:") subtitle = st.text_input("Enter subtitle:") num_slides = st.number_input("Number of slides", min_value=1, max_value=10, value=1) slides = [] for i in range(num_slides): slide_title = st.text_input(f"Slide {i+1} title:") slide_prompt = st.text_input(f"Slide {i+1} prompt:") if st.button(f"Generate Content for Slide {i+1}"): content = generate_content(slide_prompt) slides.append({'title': slide_title, 'content': content}) if st.button("Generate Presentation"): content_dict = { 'title': title, 'subtitle': subtitle, 'slides': slides } pptx_file = "output.pptx" create_presentation(content_dict, pptx_file) pdf_file = "output.pdf" convert_to_pdf(pptx_file, pdf_file) st.success("Presentation generated successfully!") # Provide download links with open(pptx_file, "rb") as file: btn = st.download_button( label="Download PPTX", data=file, file_name="presentation.pptx" ) with open(pdf_file, "rb") as file: btn = st.download_button( label="Download PDF", data=file, file_name="presentation.pdf" ) if __name__ == "__main__": main()