Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,131 +1,111 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
from
|
|
|
4 |
import streamlit as st
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
llm = LLM(
|
12 |
model="gemini/gemini-1.5-flash",
|
13 |
temperature=0.7,
|
14 |
-
timeout=120,
|
15 |
max_tokens=8000,
|
|
|
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 |
-
st.
|
106 |
-
|
107 |
-
|
108 |
-
)
|
109 |
-
|
110 |
-
# Entrée de l'utilisateur
|
111 |
-
theme = st.text_input("Entrez le thème de votre exposé :", value="Exemple : L'intelligence artificielle dans l'éducation")
|
112 |
-
|
113 |
-
# Bouton de génération
|
114 |
-
if st.button("Générer l'exposé"):
|
115 |
-
st.info("Génération de l'exposé en cours, cela peut prendre quelques instants...")
|
116 |
-
try:
|
117 |
-
# Lancement de la Crew avec le thème donné
|
118 |
-
result = crew.kickoff(inputs={"theme": theme})
|
119 |
-
|
120 |
-
# Récupération et affichage du fichier PDF généré
|
121 |
-
pdf_file_path = result.tasks_output[-1].raw
|
122 |
-
with open(pdf_file_path, "rb") as pdf_file:
|
123 |
-
st.success("Exposé généré avec succès !")
|
124 |
-
st.download_button(
|
125 |
-
label="Télécharger l'exposé au format PDF",
|
126 |
-
data=pdf_file,
|
127 |
-
file_name="expose_final.pdf",
|
128 |
-
mime="application/pdf",
|
129 |
-
)
|
130 |
-
except Exception as e:
|
131 |
-
st.error(f"Une erreur est survenue : {e}")
|
|
|
1 |
+
# presentation_generator.py
|
2 |
+
|
3 |
+
from crewai import Crew, LLM, SerperDevTool, Agent
|
4 |
+
from crewai.tools import Tool
|
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 |
+
SERPERDEV_API_KEY = "YOUR_SERPERDEV_API_KEY"
|
12 |
|
13 |
llm = LLM(
|
14 |
model="gemini/gemini-1.5-flash",
|
15 |
temperature=0.7,
|
16 |
+
timeout=120,
|
17 |
max_tokens=8000,
|
18 |
+
api_key=GEMINI_API_KEY
|
19 |
)
|
20 |
|
21 |
+
serper_tool = SerperDevTool(api_key=SERPERDEV_API_KEY)
|
22 |
+
|
23 |
+
# Plan Generator Agent
|
24 |
+
class PlanGeneratorAgent(Agent):
|
25 |
+
def __init__(self):
|
26 |
+
super().__init__(
|
27 |
+
name="PlanGenerator",
|
28 |
+
description="Generates a detailed plan for a presentation.",
|
29 |
+
llm=llm,
|
30 |
+
tools=[serper_tool]
|
31 |
+
)
|
32 |
+
|
33 |
+
def run(self, theme):
|
34 |
+
# Use serper_tool to research
|
35 |
+
research = serper_tool.search(query=f"Best practices for {theme} presentations")
|
36 |
+
# Generate plan based on research
|
37 |
+
plan = "Introduction\nMain Points\nConclusion"
|
38 |
+
return plan
|
39 |
+
|
40 |
+
# Content Generator Agent
|
41 |
+
class ContentGeneratorAgent(Agent):
|
42 |
+
def __init__(self):
|
43 |
+
super().__init__(
|
44 |
+
name="ContentGenerator",
|
45 |
+
description="Generates content for a specific section of a presentation.",
|
46 |
+
llm=llm
|
47 |
+
)
|
48 |
+
|
49 |
+
def run(self, section):
|
50 |
+
# Generate content logic
|
51 |
+
content = f"Content for {section}"
|
52 |
+
return content
|
53 |
+
|
54 |
+
# PDF Compiler Agent
|
55 |
+
class PDFCompilerAgent(Agent):
|
56 |
+
def __init__(self):
|
57 |
+
super().__init__(
|
58 |
+
name="PDFCompiler",
|
59 |
+
description="Compiles presentation content into a PDF.",
|
60 |
+
llm=llm
|
61 |
+
)
|
62 |
+
|
63 |
+
def run(self, content):
|
64 |
+
# Compile PDF logic
|
65 |
+
doc = pdfium.PdfDocument.new()
|
66 |
+
page = doc.new_page(width=612, height=792)
|
67 |
+
canvas = page.get_canvas()
|
68 |
+
# Add content to the page
|
69 |
+
doc.save("presentation.pdf")
|
70 |
+
return "presentation.pdf"
|
71 |
+
|
72 |
+
# Main Crew
|
73 |
+
class PresentationCrew(Crew):
|
74 |
+
def __init__(self):
|
75 |
+
super().__init__(
|
76 |
+
name="PresentationGenerator",
|
77 |
+
description="Generates a high-quality presentation based on a given theme.",
|
78 |
+
llm=llm,
|
79 |
+
agents=[PlanGeneratorAgent(), ContentGeneratorAgent(), PDFCompilerAgent()]
|
80 |
+
)
|
81 |
+
|
82 |
+
def run(self, theme):
|
83 |
+
plan = self.delegate("Generate a detailed plan for the presentation on {}".format(theme))
|
84 |
+
sections = plan.split("\n")
|
85 |
+
content = []
|
86 |
+
for section in sections:
|
87 |
+
if section:
|
88 |
+
content.append(self.delegate("Generate content for the presentation section: {}".format(section)))
|
89 |
+
pdf = self.delegate("Compile the following content into a PDF: {}".format("\n".join(content)))
|
90 |
+
return pdf
|
91 |
+
|
92 |
+
# Streamlit App
|
93 |
+
def get_pdf_download_link(pdf_path):
|
94 |
+
with open(pdf_path, "rb") as f:
|
95 |
+
pdf_bytes = f.read()
|
96 |
+
encoded = base64.b64encode(pdf_bytes).decode()
|
97 |
+
return f'<a href="data:application/pdf;base64,{encoded}" download="presentation.pdf">Download PDF</a>'
|
98 |
+
|
99 |
+
def main():
|
100 |
+
st.title("Advanced Presentation Generator")
|
101 |
+
|
102 |
+
theme = st.text_input("Enter the presentation theme:")
|
103 |
+
|
104 |
+
if st.button("Generate Presentation"):
|
105 |
+
crew = PresentationCrew()
|
106 |
+
pdf_path = crew.run(theme)
|
107 |
+
st.success("Presentation generated successfully!")
|
108 |
+
st.markdown(get_pdf_download_link(pdf_path), unsafe_allow_html=True)
|
109 |
+
|
110 |
+
if __name__ == "__main__":
|
111 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|