Spaces:
Sleeping
Sleeping
Create plan_generator.py
Browse files- components/plan_generator.py +28 -16
components/plan_generator.py
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
from langchain_groq import ChatGroq
|
| 3 |
-
from langchain.prompts import ChatPromptTemplate
|
| 4 |
-
from utils.prompts import STRATEGY_PROMPT
|
| 5 |
from utils.session import get_canvas_data
|
|
|
|
| 6 |
from utils.helpers import generate_pdf
|
| 7 |
|
|
|
|
| 8 |
def run_plan_generator():
|
| 9 |
st.header("๐ Auto Plan Generator")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
if not
|
| 13 |
st.warning("Please complete the Canvas Assistant first.")
|
| 14 |
return
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
st.markdown(result.content)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# components/plan_generator.py
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
+
from langchain_core.runnables import Runnable
|
| 6 |
from langchain_groq import ChatGroq
|
|
|
|
|
|
|
| 7 |
from utils.session import get_canvas_data
|
| 8 |
+
from utils.prompts import STRATEGY_PROMPT
|
| 9 |
from utils.helpers import generate_pdf
|
| 10 |
|
| 11 |
+
|
| 12 |
def run_plan_generator():
|
| 13 |
st.header("๐ Auto Plan Generator")
|
| 14 |
|
| 15 |
+
canvas = get_canvas_data()
|
| 16 |
+
if not canvas:
|
| 17 |
st.warning("Please complete the Canvas Assistant first.")
|
| 18 |
return
|
| 19 |
|
| 20 |
+
# Display Canvas Summary
|
| 21 |
+
st.subheader("๐งพ Your Canvas Summary")
|
| 22 |
+
for section, content in canvas.items():
|
| 23 |
+
st.markdown(f"**{section}**")
|
| 24 |
+
st.info(content)
|
| 25 |
+
|
| 26 |
+
with st.spinner("Generating business plan..."):
|
| 27 |
+
prompt = ChatPromptTemplate.from_template(
|
| 28 |
+
STRATEGY_PROMPT + "\n\nCanvas Data:\n{input}"
|
| 29 |
+
)
|
| 30 |
+
chain: Runnable = prompt | ChatGroq(model="llama3-8b-8192", temperature=0.4)
|
| 31 |
+
full_canvas_text = "\n".join([f"{k}: {v}" for k, v in canvas.items()])
|
| 32 |
+
result = chain.invoke({"input": full_canvas_text})
|
| 33 |
|
| 34 |
+
st.subheader("๐ Generated Business Plan")
|
| 35 |
+
st.success(result.content)
|
|
|
|
| 36 |
|
| 37 |
+
# Allow download
|
| 38 |
+
pdf_path = generate_pdf(result.content , content)
|
| 39 |
+
with open(pdf_path, "rb") as f:
|
| 40 |
+
st.download_button("๐ฅ Download as PDF", f, file_name="Business_Plan.pdf")
|
| 41 |
+
|