Spaces:
Sleeping
Sleeping
Create components/plan_generator.py
Browse files- components/plan_generator.py +37 -0
components/plan_generator.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# components/plan_generator.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from langchain_groq import ChatGroq
|
| 5 |
+
from langchain.prompts import ChatPromptTemplate
|
| 6 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 7 |
+
import os
|
| 8 |
+
from utils.prompts import STRATEGY_PROMPT
|
| 9 |
+
from utils.helpers import generate_pdf
|
| 10 |
+
|
| 11 |
+
def run_plan_generator():
|
| 12 |
+
st.header("📑 Business Plan & Pitch Generator")
|
| 13 |
+
|
| 14 |
+
if "bmc_answers" not in st.session_state:
|
| 15 |
+
st.warning("⚠️ Please complete the Canvas Assistant first.")
|
| 16 |
+
return
|
| 17 |
+
|
| 18 |
+
st.markdown("Generating plan using your Business Model Canvas answers...")
|
| 19 |
+
|
| 20 |
+
with st.spinner("Thinking like a startup advisor..."):
|
| 21 |
+
llm = ChatGroq(
|
| 22 |
+
temperature=0.3,
|
| 23 |
+
model_name="llama3-70b-8192",
|
| 24 |
+
groq_api_key=os.getenv("GROQ_API_KEY")
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
prompt = ChatPromptTemplate.from_template(STRATEGY_PROMPT)
|
| 28 |
+
chain = prompt | llm | StrOutputParser()
|
| 29 |
+
|
| 30 |
+
full_plan = chain.invoke({"input": st.session_state.bmc_answers})
|
| 31 |
+
|
| 32 |
+
st.subheader("📘 Business Plan")
|
| 33 |
+
st.write(full_plan)
|
| 34 |
+
|
| 35 |
+
if st.button("📤 Export as PDF"):
|
| 36 |
+
generate_pdf("business_plan", full_plan)
|
| 37 |
+
st.success("✅ PDF Exported Successfully!")
|