Spaces:
Sleeping
Sleeping
File size: 6,258 Bytes
64ede54 306ca9a 64ede54 045f05a 86b4561 242ca0d 64ede54 86b4561 2d8c3aa 86b4561 2d8c3aa 242ca0d 045f05a 4a1408d 045f05a 64ede54 2d8c3aa 045f05a 2d8c3aa 045f05a 2d8c3aa 242ca0d 2d8c3aa 045f05a 2d8c3aa 242ca0d 2ac7df1 64ede54 db293c8 2d8c3aa 045f05a 36d08b8 db293c8 2b0a717 db293c8 86b4561 4a1408d 7cee295 306ca9a 7cee295 2b0a717 36d08b8 86b4561 2d8c3aa 36d08b8 86b4561 7cee295 306ca9a 7cee295 2d8c3aa 7cee295 db293c8 86b4561 2d8c3aa 36d08b8 2d8c3aa 86b4561 2d8c3aa 86b4561 2d8c3aa 36d08b8 045f05a | 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 | import json
import re
import io
import os
from datetime import datetime
from openai import OpenAI
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.lib.enums import TA_CENTER
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# validate_startup_idea
def validate_startup_idea(idea, category=None, subcategory=None):
category_text = f"Category: {category}" if category else ""
subcategory_text = f"Subcategory: {subcategory}" if subcategory else ""
prompt = f"""
You are a business analysis assistant. Analyze the following startup idea:
"{idea}"
{category_text}
{subcategory_text}
Return your analysis strictly in the following JSON format without extra text:
{{
"swot": {{
"strengths": ["bullet point", "bullet point", "bullet point", "bullet point", "bullet point"],
"weaknesses": ["bullet point", "bullet point", "bullet point", "bullet point", "bullet point"],
"opportunities": ["bullet point", "bullet point", "bullet point", "bullet point", "bullet point"],
"threats": ["bullet point", "bullet point", "bullet point", "bullet point", "bullet point"]
}},
"audience": [
"bullet point audience segment",
"bullet point audience segment",
"bullet point audience segment",
"bullet point audience segment",
"bullet point audience segment"
],
"competitors": [
{{"name": "Exact Competitor Name", "description": "Short description of why they're a competitor", "link": "https://competitor-website.com"}},
{{"name": "Exact Competitor Name", "description": "Short description", "link": "https://competitor-website.com"}},
{{"name": "Exact Competitor Name", "description": "Short description", "link": "https://competitor-website.com"}}
],
"tools_and_tips": [
{{"name": "Tool or Platform Name", "description": "What it helps with", "link": "https://link-to-tool.com"}},
{{"name": "Tool or Platform Name", "description": "What it helps with", "link": "https://link-to-tool.com"}},
{{"name": "Tool or Platform Name", "description": "What it helps with", "link": "https://link-to-tool.com"}}
],
"tools_and_resources": [
{{"name": "Resource Name", "description": "Why it’s useful", "link": "https://link-to-resource.com"}},
{{"name": "Resource Name", "description": "Why it’s useful", "link": "https://link-to-resource.com"}},
{{"name": "Resource Name", "description": "Why it’s useful", "link": "https://link-to-resource.com"}},
{{"name": "Resource Name", "description": "Why it’s useful", "link": "https://link-to-resource.com"}},
{{"name": "Resource Name", "description": "Why it’s useful", "link": "https://link-to-resource.com"}}
]
}}
Rules:
- Always include **at least 5 bullet points** for "audience" and "tools_and_resources".
- All tools, platforms, competitors, and resources must include clickable **links**.
- Be very specific and practical. Avoid generic placeholders like "Competitor A" or "use social media".
- In "tools_and_tips", name the platform (e.g., "Instagram") and the tool (e.g., "Buffer") and explain why.
"""
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a business strategy expert."},
{"role": "user", "content": prompt}
],
temperature=0.7
)
content = response.choices[0].message.content
try:
data = json.loads(content)
except json.JSONDecodeError:
raise ValueError(f"Invalid JSON format returned from AI: {content}")
swot = data.get("swot", {})
swot_scores = {}
for key in ["strengths", "weaknesses", "opportunities", "threats"]:
items = swot.get(key, [])
swot_scores[key] = len(items)
data["swot_scores"] = swot_scores
return data
# Removed generate_brand_name function completely
# generate_pdf (Removed brand_names section)
def generate_pdf(data, user_name=None, logo_path=None):
buffer = io.BytesIO()
doc = SimpleDocTemplate(buffer, pagesize=letter,
rightMargin=72, leftMargin=72,
topMargin=72, bottomMargin=18)
styles = getSampleStyleSheet()
story = []
title_style = ParagraphStyle(
name='TitleStyle',
fontSize=18,
leading=22,
alignment=TA_CENTER,
spaceAfter=14
)
if logo_path and os.path.exists(logo_path):
img = Image(logo_path, width=2*inch, height=2*inch)
img.hAlign = 'CENTER'
story.append(img)
story.append(Spacer(1, 12))
story.append(Paragraph("Startup Idea Analysis Report", title_style))
story.append(Spacer(1, 12))
current_date = datetime.now().strftime("%B %d, %Y %H:%M")
user_line = f"Prepared for: {user_name}" if user_name else "Prepared for: Anonymous User"
story.append(Paragraph(user_line, styles['Normal']))
story.append(Paragraph(f"Date: {current_date}", styles['Normal']))
story.append(Spacer(1, 12))
# Removed Brand Names Section
# Loop through other sections
for category, content in data.items():
if category == "swot_scores":
continue
story.append(Paragraph(f"<b>{category.upper()}</b>", styles['Heading2']))
story.append(Spacer(1, 0.1 * inch))
if isinstance(content, list):
for item in content:
if isinstance(item, dict):
text = f"• <b>{item['name']}</b>: {item['description']} (<a href='{item['link']}' color='blue'>{item['link']}</a>)"
else:
text = f"• {item}"
story.append(Paragraph(text, styles['Normal']))
elif isinstance(content, dict):
for subcategory, bullets in content.items():
story.append(Paragraph(f"<b>{subcategory.capitalize()}</b>", styles['Heading3']))
for bullet in bullets:
story.append(Paragraph(f"• {bullet}", styles['Normal']))
story.append(Spacer(1, 0.2 * inch))
doc.build(story)
buffer.seek(0)
return buffer.getvalue()
|