File size: 7,174 Bytes
b2ee0a4
f96911c
b2ee0a4
 
a38df1c
 
b2ee0a4
 
 
 
 
 
 
 
 
a38df1c
b2ee0a4
 
a38df1c
b2ee0a4
 
 
a38df1c
b2ee0a4
a38df1c
 
b2ee0a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a38df1c
b2ee0a4
 
a38df1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2ee0a4
 
 
 
a38df1c
b2ee0a4
 
 
 
 
 
a38df1c
b2ee0a4
a38df1c
b2ee0a4
 
 
a38df1c
 
b2ee0a4
a38df1c
 
b2ee0a4
 
a38df1c
b2ee0a4
 
 
 
 
 
 
 
 
 
 
 
 
a38df1c
b2ee0a4
 
 
a38df1c
b2ee0a4
 
a38df1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2ee0a4
 
a38df1c
 
 
 
 
b2ee0a4
a38df1c
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import streamlit as st
from docx import Document
import re
import io
import os
from fpdf import FPDF
from groq import Groq
from exa_py import Exa
from dotenv import load_dotenv
from retrying import retry
from funtions import *

# Load environment variables from .env file
load_dotenv()

# Declare the exa search API
exa = Exa(api_key=os.getenv("EXA_API_KEY"))

# Define your API Model and key
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
utilized_model = "llama3-70b-8192"

# Functions for the Exa Search content & Parameters for Highlights search
highlights_options = {
    "num_sentences": 7,  # Length of highlights
    "highlights_per_url": 1,  # Get the best highlight for each URL
}

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def call_llm(prompt):
    search_response = exa.search_and_contents(query=prompt, highlights=highlights_options, num_results=3, use_autoprompt=True)
    info = [sr.highlights[0] for sr in search_response.results]
    
    system_prompt = "You are a Business proposal generator. Read the provided contexts and, if relevant, use them to answer the user's question."
    user_prompt = f"Sources: {info}\nQuestion: {prompt}"
    
    completion = client.chat.completions.create(
        model=utilized_model,
        messages=[
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": user_prompt},
        ]
    )
    return completion.choices[0].message.content

def strip_md(text):
    text = text.replace("**", "").replace("*", "").replace("#", "")
    return re.sub(r'([!*_=~-])', r'\\\1', text)

def create_document():
    doc = Document()
    doc.add_heading("Business Proposal", 0)
    return doc

def add_section_to_doc(doc, section_name, section_content):
    section_content = strip_md(section_content)
    section_content = section_content.replace("\\", "")  # Remove backslashes
    doc.add_heading(section_name, level=1)
    doc.add_paragraph(section_content)
    return doc

def get_docx_bytes(doc):
    doc_io = io.BytesIO()
    doc.save(doc_io)
    doc_io.seek(0)
    return doc_io

def collect_basic_info():
    st.title("Business Proposal Generator")

    # Basic Company Information
    company_name = st.text_input("Company Name")
    industry = st.text_input("Industry")
    location = st.text_input("Location")
    mission = st.text_area("Mission Statement")
    vision = st.text_area("Vision Statement")
    products_services = st.text_area("Description of Products/Services")
    target_market = st.text_area("Customer Segments")
    value_proposition = st.text_area("Competitive Advantage")
    promotional_strategy = st.text_area("Promotional Strategy")
    current_revenue = st.number_input("Current Revenue (R)", min_value=0.0, format="%f")
    current_expenses = st.number_input("Current Expenses (R)", min_value=0.0, format="%f")
    funding_requirements = st.text_area("Funding Requirements")
    management_team = st.text_area("Key Personnel")
    company_structure = st.text_area("Company Structure")
    goals_objectives = st.text_area("Short-term and Long-term Goals")
    operational_strategy = st.text_area("Operational Strategy")
    market_overview = st.text_area("Market Overview")

    if st.button('Submit'):
        # Collect data
        data = {
            "company_name": company_name,
            "industry": industry,
            "location": location,
            "mission": mission,
            "vision": vision,
            "products_services": products_services,
            "target_market": target_market,
            "value_proposition": value_proposition,
            "current_revenue": current_revenue,
            "current_expenses": current_expenses,
            "funding_requirements": funding_requirements,
            "management_team": management_team,
            "company_structure": company_structure,
            "goals_objectives": goals_objectives,
            "operational_strategy": operational_strategy,
            "market_overview": market_overview,
            "promotional_strategy": promotional_strategy
        }

        # Create a new document
        doc = create_document()

        # Process and update document with each section
        sections_to_process = [
            ("Executive Summary", generate_executive_summary),
            ("Mission Statement", generate_mission),
            ("Vision Statement", generate_vision),
            ("Objectives", generate_objectives),
            ("Core Values", generate_core_values),
            ("Business Description Analysis", generate_business_description),
            ("Company Location", generate_company_location),
            ("Products", generate_products),
            ("Ownership", generate_ownership),
            ("Company Structure", generate_company_structure),
            ("Management Profiles", generate_management_profiles),
            ("Operational Strategy", generate_operational_strategy),
            ("Marketing Mix Strategy", generate_marketing_mix),
            ("Promotional Strategy", generate_promotional_strategy),
            ("Market Demand Analysis", analyze_demand),
            ("Market Segment Analysis", segment_market),
            ("Competitor Analysis", analyze_competitors),
            ("Porter's Five Forces Analysis", perform_porters_five_forces),
            ("Industry Analysis", analyze_industry_accommodation),
            ("Major Player Analysis", list_major_players),
            ("Business Sub Sector Analysis", analyze_business_sub_sector),
            ("SWOT Analysis", generate_swot_analysis),
            ("Funding Request", generate_funding_request),
            ("Financing & Bank Loan Amortization", create_financing_plan),
            ("Income Statement Analysis", generate_pro_forma_income_statement),
            ("Revenue Expense Analysis", predict_revenue_expenses),
            ("Montly Cash Flow Analysis", generate_monthly_cash_flow),
            ("Pro Forma Annual Cash Flow Analysis", generate_pro_forma_annual_cash_flow),
            ("Pro Forma Balance Sheet Analysis", generate_pro_forma_balance_sheet),
            ("Break-Even Analysis", perform_break_even_analysis),
            ("Payback Period Analysis", calculate_payback_period),
            ("Financial Graphs Analysis", generate_financial_graphs),
            ("Risk Mitigations Analysis", identify_risks_mitigations)
        ]

        for section_name, generate_prompt_func in sections_to_process:
            prompt = generate_prompt_func(data)
            section_content = call_llm(prompt)
            st.subheader(section_name)
            st.write(section_content)
            
            # Update document and create download link
            doc = add_section_to_doc(doc, section_name, section_content)
            doc_bytes = get_docx_bytes(doc)

            st.download_button(
                label=f"Download {section_name} as DOCX",
                data=doc_bytes,
                file_name=f"{section_name.replace(' ', '_').lower()}.docx",
                mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            )

collect_basic_info()