Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1 |
# presentation_generator.py
|
|
|
2 |
import os
|
3 |
from crewai import Crew, LLM, Agent
|
4 |
from crewai_tools import Tool, SerperDevTool
|
5 |
import streamlit as st
|
6 |
import base64
|
7 |
import pypdfium2 as pdfium
|
|
|
8 |
|
9 |
# Replace with your actual API keys
|
10 |
GEMINI_API_KEY = "AIzaSyD6yZxfVOnh63GXBJjakAupk9aP4CZrgrQ"
|
11 |
SERPER_API_KEY = "9b90a274d9e704ff5b21c0367f9ae1161779b573"
|
|
|
12 |
llm = LLM(
|
13 |
model="gemini/gemini-1.5-flash",
|
14 |
temperature=0.7,
|
@@ -17,7 +20,7 @@ llm = LLM(
|
|
17 |
api_key=GEMINI_API_KEY
|
18 |
)
|
19 |
|
20 |
-
serper_tool = SerperDevTool(api_key=
|
21 |
|
22 |
# Plan Generator Agent
|
23 |
class PlanGeneratorAgent(Agent):
|
@@ -45,10 +48,10 @@ class ContentGeneratorAgent(Agent):
|
|
45 |
llm=llm
|
46 |
)
|
47 |
|
48 |
-
def run(self, section):
|
49 |
# Generate content logic
|
50 |
-
|
51 |
-
|
52 |
return content
|
53 |
|
54 |
# PDF Compiler Agent
|
@@ -60,13 +63,17 @@ class PDFCompilerAgent(Agent):
|
|
60 |
llm=llm
|
61 |
)
|
62 |
|
63 |
-
def run(self,
|
64 |
# Compile PDF logic
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
70 |
return "presentation.pdf"
|
71 |
|
72 |
# Main Crew
|
@@ -80,14 +87,24 @@ class PresentationCrew(Crew):
|
|
80 |
)
|
81 |
|
82 |
def run(self, theme):
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
# Streamlit App
|
93 |
def get_pdf_download_link(pdf_path):
|
@@ -104,8 +121,11 @@ def main():
|
|
104 |
if st.button("Generate Presentation"):
|
105 |
crew = PresentationCrew()
|
106 |
pdf_path = crew.run(theme)
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
109 |
|
110 |
if __name__ == "__main__":
|
111 |
main()
|
|
|
1 |
# presentation_generator.py
|
2 |
+
|
3 |
import os
|
4 |
from crewai import Crew, LLM, Agent
|
5 |
from crewai_tools import Tool, SerperDevTool
|
6 |
import streamlit as st
|
7 |
import base64
|
8 |
import pypdfium2 as pdfium
|
9 |
+
from fpdf import FPDF
|
10 |
|
11 |
# Replace with your actual API keys
|
12 |
GEMINI_API_KEY = "AIzaSyD6yZxfVOnh63GXBJjakAupk9aP4CZrgrQ"
|
13 |
SERPER_API_KEY = "9b90a274d9e704ff5b21c0367f9ae1161779b573"
|
14 |
+
|
15 |
llm = LLM(
|
16 |
model="gemini/gemini-1.5-flash",
|
17 |
temperature=0.7,
|
|
|
20 |
api_key=GEMINI_API_KEY
|
21 |
)
|
22 |
|
23 |
+
serper_tool = SerperDevTool(api_key=SERPERDEV_API_KEY)
|
24 |
|
25 |
# Plan Generator Agent
|
26 |
class PlanGeneratorAgent(Agent):
|
|
|
48 |
llm=llm
|
49 |
)
|
50 |
|
51 |
+
def run(self, section, theme):
|
52 |
# Generate content logic
|
53 |
+
prompt = f"Generate {section} for a presentation on {theme}."
|
54 |
+
content = self.llm.generate(prompt)
|
55 |
return content
|
56 |
|
57 |
# PDF Compiler Agent
|
|
|
63 |
llm=llm
|
64 |
)
|
65 |
|
66 |
+
def run(self, content_dict):
|
67 |
# Compile PDF logic
|
68 |
+
pdf = FPDF()
|
69 |
+
pdf.add_page()
|
70 |
+
pdf.set_font("Arial", size=12)
|
71 |
+
|
72 |
+
for section, content in content_dict.items():
|
73 |
+
pdf.cell(0, 10, f"{section}", ln=True)
|
74 |
+
pdf.multi_cell(0, 10, f"{content}", ln=True)
|
75 |
+
|
76 |
+
pdf.output("presentation.pdf")
|
77 |
return "presentation.pdf"
|
78 |
|
79 |
# Main Crew
|
|
|
87 |
)
|
88 |
|
89 |
def run(self, theme):
|
90 |
+
try:
|
91 |
+
# Generate plan
|
92 |
+
plan = self.delegate("Generate a detailed plan for the presentation on {}".format(theme))
|
93 |
+
sections = plan.split("\n")
|
94 |
+
content_dict = {}
|
95 |
+
|
96 |
+
# Generate content for each section
|
97 |
+
for section in sections:
|
98 |
+
if section:
|
99 |
+
content = self.delegate("Generate content for the presentation section: {}".format(section), theme=theme)
|
100 |
+
content_dict[section] = content
|
101 |
+
|
102 |
+
# Compile PDF
|
103 |
+
pdf_path = self.delegate("Compile the following content into a PDF: {}".format(content_dict))
|
104 |
+
return pdf_path
|
105 |
+
except Exception as e:
|
106 |
+
print(f"An error occurred: {e}")
|
107 |
+
return None
|
108 |
|
109 |
# Streamlit App
|
110 |
def get_pdf_download_link(pdf_path):
|
|
|
121 |
if st.button("Generate Presentation"):
|
122 |
crew = PresentationCrew()
|
123 |
pdf_path = crew.run(theme)
|
124 |
+
if pdf_path:
|
125 |
+
st.success("Presentation generated successfully!")
|
126 |
+
st.markdown(get_pdf_download_link(pdf_path), unsafe_allow_html=True)
|
127 |
+
else:
|
128 |
+
st.error("Failed to generate presentation.")
|
129 |
|
130 |
if __name__ == "__main__":
|
131 |
main()
|