File size: 3,535 Bytes
85e590f
814d355
a99cdc3
a8ead94
0a6c0de
85e590f
 
 
 
 
55de6ef
154424a
 
 
85e590f
154424a
85e590f
154424a
 
85e590f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4234b32
85e590f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# presentation_generator.py
import os
from crewai import Crew, LLM, Agent
from crewai_tools import Tool, SerperDevTool
import streamlit as st
import base64
import pypdfium2 as pdfium

# Replace with your actual API keys
GEMINI_API_KEY = "AIzaSyD6yZxfVOnh63GXBJjakAupk9aP4CZrgrQ"
os.environ["SERPER_API_KEY"] = "9b90a274d9e704ff5b21c0367f9ae1161779b573"
llm = LLM(
    model="gemini/gemini-1.5-flash",
    temperature=0.7,
    timeout=120,
    max_tokens=8000,
    api_key=GEMINI_API_KEY
)

serper_tool = SerperDevTool(api_key=SERPERDEV_API_KEY)

# Plan Generator Agent
class PlanGeneratorAgent(Agent):
    def __init__(self):
        super().__init__(
            name="PlanGenerator",
            description="Generates a detailed plan for a presentation.",
            llm=llm,
            tools=[serper_tool]
        )

    def run(self, theme):
        # Use serper_tool to research
        research = serper_tool.search(query=f"Best practices for {theme} presentations")
        # Generate plan based on research
        plan = "Introduction\nMain Points\nConclusion"
        return plan

# Content Generator Agent
class ContentGeneratorAgent(Agent):
    def __init__(self):
        super().__init__(
            name="ContentGenerator",
            description="Generates content for a specific section of a presentation.",
            llm=llm
        )

    def run(self, section):
        # Generate content logic
        content = f"Content for {section}"
        print(content)
        return content

# PDF Compiler Agent
class PDFCompilerAgent(Agent):
    def __init__(self):
        super().__init__(
            name="PDFCompiler",
            description="Compiles presentation content into a PDF.",
            llm=llm
        )

    def run(self, content):
        # Compile PDF logic
        doc = pdfium.PdfDocument.new()
        page = doc.new_page(width=612, height=792)
        canvas = page.get_canvas()
        # Add content to the page
        doc.save("presentation.pdf")
        return "presentation.pdf"

# Main Crew
class PresentationCrew(Crew):
    def __init__(self):
        super().__init__(
            name="PresentationGenerator",
            description="Generates a high-quality presentation based on a given theme.",
            llm=llm,
            agents=[PlanGeneratorAgent(), ContentGeneratorAgent(), PDFCompilerAgent()]
        )

    def run(self, theme):
        plan = self.delegate("Generate a detailed plan for the presentation on {}".format(theme))
        sections = plan.split("\n")
        content = []
        for section in sections:
            if section:
                content.append(self.delegate("Generate content for the presentation section: {}".format(section)))
        pdf = self.delegate("Compile the following content into a PDF: {}".format("\n".join(content)))
        return pdf

# Streamlit App
def get_pdf_download_link(pdf_path):
    with open(pdf_path, "rb") as f:
        pdf_bytes = f.read()
    encoded = base64.b64encode(pdf_bytes).decode()
    return f'<a href="data:application/pdf;base64,{encoded}" download="presentation.pdf">Download PDF</a>'

def main():
    st.title("Advanced Presentation Generator")

    theme = st.text_input("Enter the presentation theme:")

    if st.button("Generate Presentation"):
        crew = PresentationCrew()
        pdf_path = crew.run(theme)
        st.success("Presentation generated successfully!")
        st.markdown(get_pdf_download_link(pdf_path), unsafe_allow_html=True)

if __name__ == "__main__":
    main()