AsthanM commited on
Commit
e5788d1
Β·
verified Β·
1 Parent(s): cd6c436

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +116 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import matplotlib.pyplot as plt
7
+ from fpdf import FPDF
8
+ from io import BytesIO
9
+ from streamlit_lottie import st_lottie
10
+ import requests
11
+
12
+ # Load Lottie animation
13
+ def load_lottieurl(url):
14
+ r = requests.get(url)
15
+ if r.status_code != 200:
16
+ return None
17
+ return r.json()
18
+
19
+ # Page config
20
+ st.set_page_config(page_title="Competitive Product Analyser", layout="wide")
21
+
22
+ # Hero header
23
+ st.markdown("""
24
+ <div style='background: linear-gradient(90deg, #ff4b4b, #ff6e6e);
25
+ padding: 30px;
26
+ border-radius: 10px;
27
+ text-align: center;
28
+ color: white;
29
+ font-size: 28px;
30
+ font-weight: bold'>
31
+ πŸš€ Competitive Product Analyser
32
+ </div>
33
+ """, unsafe_allow_html=True)
34
+
35
+ st.markdown("### Compare two products or services and generate a full analysis including feature comparisons, SWOT, and more.")
36
+ st.markdown("---")
37
+
38
+ # Set token
39
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
40
+
41
+ # Model setup
42
+ llm = HuggingFaceHub(
43
+ repo_id="tiiuae/falcon-7b-instruct",
44
+ model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
45
+ )
46
+
47
+ template = """
48
+ Compare the following two products or services:
49
+ Product 1:
50
+ {product1}
51
+ Product 2:
52
+ {product2}
53
+ Instructions:
54
+ 1. Provide a feature-by-feature comparison.
55
+ 2. Generate a SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis for each.
56
+ 3. Summarize key differentiators between them.
57
+ """
58
+
59
+ prompt = PromptTemplate(input_variables=["product1", "product2"], template=template)
60
+ comparison_chain = LLMChain(llm=llm, prompt=prompt)
61
+
62
+ # Input layout
63
+ col1, col2 = st.columns(2)
64
+ with col1:
65
+ product1 = st.text_area("🧩 Product/Service 1", height=200, placeholder="Describe Product 1...")
66
+ with col2:
67
+ product2 = st.text_area("🧩 Product/Service 2", height=200, placeholder="Describe Product 2...")
68
+
69
+ # Compare Button
70
+ if st.button("βš”οΈ Compare Now", use_container_width=True):
71
+ if not product1 or not product2:
72
+ st.warning("Please enter descriptions for both products.")
73
+ else:
74
+ with st.spinner("πŸ€– Analyzing with LLM..."):
75
+ result = comparison_chain.run(product1=product1, product2=product2)
76
+
77
+ # Output display
78
+ st.subheader("πŸ“Š AI-Generated Competitive Analysis")
79
+ st.markdown(f"""<div style='background-color:#f9f9f9;padding:20px;border-radius:10px;'>{result}</div>""", unsafe_allow_html=True)
80
+
81
+ # Word count metrics
82
+ col1, col2 = st.columns(2)
83
+ col1.metric("πŸ“„ Product 1 Words", f"{len(product1.split())}")
84
+ col2.metric("πŸ“„ Product 2 Words", f"{len(product2.split())}")
85
+
86
+ # Chart
87
+ st.markdown("### πŸ”’ Word Count Comparison")
88
+ fig, ax = plt.subplots()
89
+ ax.bar(["Product 1", "Product 2"], [len(product1.split()), len(product2.split())], color=["skyblue", "salmon"])
90
+ ax.set_ylabel("Word Count")
91
+ ax.set_title("Word Count Chart")
92
+ st.pyplot(fig)
93
+
94
+ # PDF Report
95
+ pdf = FPDF()
96
+ pdf.add_page()
97
+ pdf.set_font("Arial", size=12)
98
+ pdf.multi_cell(0, 10, txt="Competitive Analysis Report\n\n" + result)
99
+ pdf_bytes = pdf.output(dest='S').encode('latin1')
100
+ pdf_output = BytesIO(pdf_bytes)
101
+
102
+ st.download_button(
103
+ label="πŸ“₯ Download PDF Report",
104
+ data=pdf_output,
105
+ file_name="competitive_analysis_report.pdf",
106
+ mime="application/pdf",
107
+ use_container_width=True
108
+ )
109
+
110
+ # Footer
111
+ st.markdown("""
112
+ ---
113
+ <div style='text-align: center; color: gray; font-size: 14px;'>
114
+ Made with ❀️ using Streamlit, LangChain, and Hugging Face.
115
+ </div>
116
+ """, unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ requests
3
+ matplotlib
4
+ fpdf
5
+ langchain
6
+ streamlit-lottie