Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,17 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from langchain_community.llms import HuggingFaceHub
|
| 3 |
-
from langchain.prompts import PromptTemplate
|
| 4 |
-
from langchain.chains import LLMChain
|
| 5 |
import os
|
| 6 |
from fpdf import FPDF
|
| 7 |
from io import BytesIO
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
st.set_page_config(page_title="Pro Competitive Analysis
|
| 11 |
|
| 12 |
-
#
|
| 13 |
st.markdown("""
|
| 14 |
<style>
|
| 15 |
body {
|
| 16 |
-
background-color: #111;
|
| 17 |
color: #e0e0e0;
|
| 18 |
font-family: 'Segoe UI', sans-serif;
|
| 19 |
}
|
|
@@ -38,54 +36,58 @@ button:hover {
|
|
| 38 |
</style>
|
| 39 |
""", unsafe_allow_html=True)
|
| 40 |
|
|
|
|
| 41 |
st.title("πΌ Competitive Analysis Pro")
|
| 42 |
-
st.markdown("
|
| 43 |
|
| 44 |
-
#
|
| 45 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
|
| 46 |
|
| 47 |
-
#
|
| 48 |
llm = HuggingFaceHub(
|
| 49 |
repo_id="tiiuae/falcon-7b-instruct",
|
| 50 |
model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
|
| 51 |
)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
template = """
|
| 55 |
-
You are a professional market analyst. Analyze the two following products/services.
|
| 56 |
-
|
| 57 |
-
Product 1:
|
| 58 |
-
{product1}
|
| 59 |
-
|
| 60 |
-
Product 2:
|
| 61 |
-
{product2}
|
| 62 |
-
|
| 63 |
-
Instructions:
|
| 64 |
-
1. Provide a detailed feature-by-feature comparison (performance, pricing, usability, support, integrations, etc.).
|
| 65 |
-
2. Conduct a comprehensive SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis for each.
|
| 66 |
-
3. Offer business insights, use cases, and suggestions for each.
|
| 67 |
-
4. Summarize the key differentiators and recommend which is better for different types of users or companies.
|
| 68 |
-
Use professional tone and structured markdown formatting (with bold headings and bullet points).
|
| 69 |
-
"""
|
| 70 |
-
|
| 71 |
-
prompt = PromptTemplate(input_variables=["product1", "product2"], template=template)
|
| 72 |
-
comparison_chain = LLMChain(llm=llm, prompt=prompt)
|
| 73 |
-
|
| 74 |
-
# Input UI
|
| 75 |
product1 = st.text_area("π§© Product/Service 1", height=200, placeholder="e.g., Salesforce CRM")
|
| 76 |
product2 = st.text_area("π§© Product/Service 2", height=200, placeholder="e.g., Zoho CRM")
|
| 77 |
|
|
|
|
| 78 |
if st.button("π Run Competitive Analysis", use_container_width=True):
|
| 79 |
if not product1 or not product2:
|
| 80 |
st.warning("Please enter descriptions for both products.")
|
| 81 |
else:
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
|
|
|
| 86 |
st.markdown(result)
|
| 87 |
|
| 88 |
-
# PDF
|
| 89 |
pdf = FPDF()
|
| 90 |
pdf.add_page()
|
| 91 |
pdf.set_font("Arial", size=12)
|
|
@@ -94,7 +96,7 @@ if st.button("π Run Competitive Analysis", use_container_width=True):
|
|
| 94 |
pdf_output = BytesIO(pdf_bytes)
|
| 95 |
|
| 96 |
st.download_button(
|
| 97 |
-
label="π₯ Download
|
| 98 |
data=pdf_output,
|
| 99 |
file_name="competitive_analysis_report.pdf",
|
| 100 |
mime="application/pdf",
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from langchain_community.llms import HuggingFaceHub
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
from fpdf import FPDF
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
+
# π¨ Streamlit page setup
|
| 8 |
+
st.set_page_config(page_title="Pro Competitive Analysis", layout="centered")
|
| 9 |
|
| 10 |
+
# π
Custom dark styling
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
body {
|
| 14 |
+
background-color: #111 !important;
|
| 15 |
color: #e0e0e0;
|
| 16 |
font-family: 'Segoe UI', sans-serif;
|
| 17 |
}
|
|
|
|
| 36 |
</style>
|
| 37 |
""", unsafe_allow_html=True)
|
| 38 |
|
| 39 |
+
# π§ Header
|
| 40 |
st.title("πΌ Competitive Analysis Pro")
|
| 41 |
+
st.markdown("Generate expert-level insights between two competing products or services.")
|
| 42 |
|
| 43 |
+
# ποΈ Hugging Face Token (set via HF secret)
|
| 44 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
|
| 45 |
|
| 46 |
+
# π§ LLM setup
|
| 47 |
llm = HuggingFaceHub(
|
| 48 |
repo_id="tiiuae/falcon-7b-instruct",
|
| 49 |
model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
|
| 50 |
)
|
| 51 |
|
| 52 |
+
# βοΈ Input fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
product1 = st.text_area("π§© Product/Service 1", height=200, placeholder="e.g., Salesforce CRM")
|
| 54 |
product2 = st.text_area("π§© Product/Service 2", height=200, placeholder="e.g., Zoho CRM")
|
| 55 |
|
| 56 |
+
# π Action
|
| 57 |
if st.button("π Run Competitive Analysis", use_container_width=True):
|
| 58 |
if not product1 or not product2:
|
| 59 |
st.warning("Please enter descriptions for both products.")
|
| 60 |
else:
|
| 61 |
+
# π¬ Instructions hidden from output
|
| 62 |
+
full_prompt = """
|
| 63 |
+
You are a professional market analyst trained to evaluate two competing products or services.
|
| 64 |
+
|
| 65 |
+
Your task is to generate an analysis in markdown format including:
|
| 66 |
+
- Feature-by-feature comparison
|
| 67 |
+
- SWOT analysis for each
|
| 68 |
+
- Business insights, use cases, and recommendations
|
| 69 |
+
- Key differentiators and user fit
|
| 70 |
+
|
| 71 |
+
Do not mention these instructions or your role. Only return the analysis.
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
# π Final prompt sent to LLM
|
| 75 |
+
final_input = full_prompt + f"""
|
| 76 |
+
|
| 77 |
+
Product 1:
|
| 78 |
+
{product1}
|
| 79 |
+
|
| 80 |
+
Product 2:
|
| 81 |
+
{product2}
|
| 82 |
+
"""
|
| 83 |
+
with st.spinner("Generating analysis..."):
|
| 84 |
+
result = llm(final_input)
|
| 85 |
|
| 86 |
+
# π§Ύ Display analysis
|
| 87 |
+
st.markdown("### π Expert Comparison")
|
| 88 |
st.markdown(result)
|
| 89 |
|
| 90 |
+
# π₯ PDF Export
|
| 91 |
pdf = FPDF()
|
| 92 |
pdf.add_page()
|
| 93 |
pdf.set_font("Arial", size=12)
|
|
|
|
| 96 |
pdf_output = BytesIO(pdf_bytes)
|
| 97 |
|
| 98 |
st.download_button(
|
| 99 |
+
label="π₯ Download Report as PDF",
|
| 100 |
data=pdf_output,
|
| 101 |
file_name="competitive_analysis_report.pdf",
|
| 102 |
mime="application/pdf",
|