Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,9 @@ 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"
|
@@ -59,30 +60,30 @@ class ContentGeneratorAgent(Agent):
|
|
59 |
content = self.llm.generate(prompt)
|
60 |
return content
|
61 |
|
62 |
-
# PDF Compiler Agent
|
63 |
-
class PDFCompilerAgent(Agent):
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
# Main Crew
|
88 |
class PresentationCrew(Crew):
|
@@ -91,32 +92,34 @@ class PresentationCrew(Crew):
|
|
91 |
name="PresentationGenerator",
|
92 |
description="Generates a high-quality presentation based on a given theme.",
|
93 |
llm=llm,
|
94 |
-
agents=[PlanGeneratorAgent(), ContentGeneratorAgent()
|
95 |
)
|
96 |
|
97 |
def run(self, theme):
|
98 |
try:
|
99 |
-
|
|
|
|
|
|
|
100 |
sections = plan.split("\n")
|
101 |
content_dict = {}
|
102 |
|
103 |
for section in sections:
|
104 |
if section:
|
105 |
-
content =
|
106 |
content_dict[section] = content
|
107 |
|
108 |
-
|
109 |
-
return pdf_path
|
110 |
except Exception as e:
|
111 |
print(f"An error occurred: {e}")
|
112 |
return None
|
113 |
|
114 |
# Streamlit App Functions
|
115 |
-
def get_pdf_download_link(pdf_path):
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
|
121 |
def main():
|
122 |
st.title("Advanced Presentation Generator")
|
@@ -125,10 +128,13 @@ def main():
|
|
125 |
|
126 |
if st.button("Generate Presentation"):
|
127 |
crew = PresentationCrew()
|
128 |
-
|
129 |
-
if
|
130 |
st.success("Presentation generated successfully!")
|
131 |
-
|
|
|
|
|
|
|
132 |
else:
|
133 |
st.error("Failed to generate presentation.")
|
134 |
|
|
|
5 |
from crewai_tools import Tool, SerperDevTool
|
6 |
import streamlit as st
|
7 |
import base64
|
8 |
+
# import pypdfium2 as pdfium # Removed
|
9 |
+
# from fpdf import FPDF # Removed
|
10 |
+
|
11 |
|
12 |
# Replace with your actual API keys
|
13 |
GEMINI_API_KEY = "AIzaSyD6yZxfVOnh63GXBJjakAupk9aP4CZrgrQ"
|
|
|
60 |
content = self.llm.generate(prompt)
|
61 |
return content
|
62 |
|
63 |
+
# PDF Compiler Agent # Removed
|
64 |
+
# class PDFCompilerAgent(Agent):
|
65 |
+
# def __init__(self):
|
66 |
+
# super().__init__(
|
67 |
+
# name="PDFCompiler",
|
68 |
+
# role="Document Formatter",
|
69 |
+
# goal="Create professional and well-formatted PDF presentations",
|
70 |
+
# backstory="""You are a document formatting expert who knows how to
|
71 |
+
# transform content into visually appealing and professional PDFs. You
|
72 |
+
# understand typography, layout, and document structure.""",
|
73 |
+
# llm=llm
|
74 |
+
# )
|
75 |
+
|
76 |
+
# def run(self, content_dict):
|
77 |
+
# pdf = FPDF()
|
78 |
+
# pdf.add_page()
|
79 |
+
# pdf.set_font("Arial", size=12)
|
80 |
+
|
81 |
+
# for section, content in content_dict.items():
|
82 |
+
# pdf.cell(0, 10, f"{section}", ln=True)
|
83 |
+
# pdf.multi_cell(0, 10, f"{content}", ln=True)
|
84 |
+
|
85 |
+
# pdf.output("presentation.pdf")
|
86 |
+
# return "presentation.pdf"
|
87 |
|
88 |
# Main Crew
|
89 |
class PresentationCrew(Crew):
|
|
|
92 |
name="PresentationGenerator",
|
93 |
description="Generates a high-quality presentation based on a given theme.",
|
94 |
llm=llm,
|
95 |
+
agents=[PlanGeneratorAgent(), ContentGeneratorAgent()] # Removed PDFCompilerAgent
|
96 |
)
|
97 |
|
98 |
def run(self, theme):
|
99 |
try:
|
100 |
+
plan_agent = self.agents[0]
|
101 |
+
content_agent = self.agents[1]
|
102 |
+
|
103 |
+
plan = plan_agent.run(theme)
|
104 |
sections = plan.split("\n")
|
105 |
content_dict = {}
|
106 |
|
107 |
for section in sections:
|
108 |
if section:
|
109 |
+
content = content_agent.run(section, theme)
|
110 |
content_dict[section] = content
|
111 |
|
112 |
+
return content_dict
|
|
|
113 |
except Exception as e:
|
114 |
print(f"An error occurred: {e}")
|
115 |
return None
|
116 |
|
117 |
# Streamlit App Functions
|
118 |
+
# def get_pdf_download_link(pdf_path): # Removed
|
119 |
+
# with open(pdf_path, "rb") as f:
|
120 |
+
# pdf_bytes = f.read()
|
121 |
+
# encoded = base64.b64encode(pdf_bytes).decode()
|
122 |
+
# return f'<a href="data:application/pdf;base64,{encoded}" download="presentation.pdf">Download PDF</a>'
|
123 |
|
124 |
def main():
|
125 |
st.title("Advanced Presentation Generator")
|
|
|
128 |
|
129 |
if st.button("Generate Presentation"):
|
130 |
crew = PresentationCrew()
|
131 |
+
presentation_content = crew.run(theme)
|
132 |
+
if presentation_content:
|
133 |
st.success("Presentation generated successfully!")
|
134 |
+
for section, content in presentation_content.items():
|
135 |
+
st.subheader(section)
|
136 |
+
st.write(content)
|
137 |
+
st.markdown("---") # Separator between sections
|
138 |
else:
|
139 |
st.error("Failed to generate presentation.")
|
140 |
|