AsthanM commited on
Commit
230c7c9
Β·
verified Β·
1 Parent(s): a7f3c27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -36
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
- # Page config
10
- st.set_page_config(page_title="Pro Competitive Analysis Tool", layout="centered")
11
 
12
- # Stylish monochrome header
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("Gain deep market insight with feature breakdowns, SWOT, and key differentiators.")
43
 
44
- # Set API key from Hugging Face Secrets
45
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
46
 
47
- # Load model
48
  llm = HuggingFaceHub(
49
  repo_id="tiiuae/falcon-7b-instruct",
50
  model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
51
  )
52
 
53
- # Prompt template
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
- with st.spinner("Analyzing with LLM..."):
83
- result = comparison_chain.run(product1=product1, product2=product2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- st.markdown("### πŸ“Š Analysis Report")
 
86
  st.markdown(result)
87
 
88
- # PDF Report
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 Full Report as PDF",
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",