File size: 2,527 Bytes
0226fdb
7aef27a
0226fdb
 
c64a253
d54ded6
7aef27a
c64a253
d54ded6
c64a253
d54ded6
 
c64a253
d54ded6
c64a253
d54ded6
0226fdb
c64a253
 
 
 
 
 
f8cf1b7
c64a253
 
 
 
 
 
 
0226fdb
d54ded6
 
 
 
0226fdb
 
d54ded6
 
 
c64a253
 
7aef27a
c64a253
 
d54ded6
 
7aef27a
c64a253
7aef27a
c64a253
 
 
d54ded6
c64a253
 
 
 
 
 
 
 
d54ded6
c64a253
 
 
 
 
2ec2ad1
 
 
d54ded6
c64a253
 
 
 
 
 
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
import streamlit as st
from langchain_community.llms import HuggingFaceHub
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import os
import matplotlib.pyplot as plt
from fpdf import FPDF
from io import BytesIO

# Set Hugging Face API token from secrets
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]

# Choose a compatible model (text-generation)
llm = HuggingFaceHub(
    repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
)

# Prompt template
template = """
Compare the following two products or services:

Product 1:
{product1}

Product 2:
{product2}

Instructions:
1. Provide a feature-by-feature comparison.
2. Generate a SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis for each.
3. Summarize key differentiators between them.
"""

prompt = PromptTemplate(
    input_variables=["product1", "product2"],
    template=template,
)

comparison_chain = LLMChain(llm=llm, prompt=prompt)

# Streamlit UI
st.title("πŸ” Competitive Analysis Tool")
st.write("Compare two products or services using LLM-powered insights.")

product1 = st.text_area("Enter Product/Service 1 Description", height=200)
product2 = st.text_area("Enter Product/Service 2 Description", height=200)

if st.button("Compare"):
    if not product1 or not product2:
        st.warning("Please enter descriptions for both products.")
    else:
        result = comparison_chain.run(product1=product1, product2=product2)
        st.subheader("πŸ“Š Comparison Results")
        st.write(result)

        # Basic chart: Number of keywords in each description (just an example)
        p1_len = len(product1.split())
        p2_len = len(product2.split())
        fig, ax = plt.subplots()
        ax.bar(["Product 1", "Product 2"], [p1_len, p2_len], color=["skyblue", "salmon"])
        ax.set_ylabel("Word Count")
        ax.set_title("Word Count Comparison")
        st.pyplot(fig)

        # Create a downloadable PDF report
        pdf = FPDF()
        pdf.add_page()
        pdf.set_font("Arial", size=12)
        pdf.multi_cell(0, 10, txt="Competitive Analysis Report\n\n" + result)
        # Generate PDF content as string and convert to BytesIO
        pdf_bytes = pdf.output(dest='S').encode('latin1')
        pdf_output = BytesIO(pdf_bytes)

        st.download_button(
            label="πŸ“₯ Download PDF Report",
            data=pdf_output,
            file_name="competitive_analysis_report.pdf",
            mime="application/pdf"
        )