AsthanM commited on
Commit
dd59a4c
Β·
verified Β·
1 Parent(s): 7706a02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -39
app.py CHANGED
@@ -7,29 +7,15 @@ import matplotlib.pyplot as plt
7
  from fpdf import FPDF
8
  from io import BytesIO
9
 
10
- # πŸ’¬ Title & Description
11
- st.set_page_config(page_title="Competitive Analysis Tool", layout="wide")
12
- st.title("πŸ” Competitive Analysis Tool")
13
- st.markdown("""
14
- Welcome to your AI-powered business analyst.
15
- Compare two products or services to receive:
16
- - 🧩 Feature-by-feature comparison
17
- - πŸ’‘ SWOT analysis
18
- - πŸ“ Key differentiators
19
- - πŸ“₯ Downloadable PDF Report
20
- """)
21
-
22
- st.markdown("---")
23
-
24
- # πŸ”’ Set API token
25
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
26
 
27
- # πŸ”— LangChain setup
28
  llm = HuggingFaceHub(
29
- repo_id="tiiuae/falcon-7b-instruct",
30
- model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
31
  )
32
 
 
33
  template = """
34
  Compare the following two products or services:
35
  Product 1:
@@ -42,32 +28,29 @@ Instructions:
42
  3. Summarize key differentiators between them.
43
  """
44
 
45
- prompt = PromptTemplate(input_variables=["product1", "product2"], template=template)
 
 
 
 
46
  comparison_chain = LLMChain(llm=llm, prompt=prompt)
47
 
48
- # 🎯 UI Layout
49
- col1, col2 = st.columns(2)
50
- with col1:
51
- product1 = st.text_area("🧩 Product/Service 1", height=200, placeholder="Describe Product 1...")
52
- with col2:
53
- product2 = st.text_area("🧩 Product/Service 2", height=200, placeholder="Describe Product 2...")
54
 
55
- st.markdown("")
 
56
 
57
- # πŸš€ Compare Button
58
- if st.button("βš”οΈ Compare Now", use_container_width=True):
59
  if not product1 or not product2:
60
  st.warning("Please enter descriptions for both products.")
61
  else:
62
- with st.spinner("πŸ€– Analyzing with LLM..."):
63
- result = comparison_chain.run(product1=product1, product2=product2)
64
-
65
- # 🧠 Display Results
66
- st.subheader("πŸ“Š AI-Generated Competitive Analysis")
67
- st.markdown(f"""<div style='background-color:#f9f9f9;padding:20px;border-radius:10px;'>{result}</div>""", unsafe_allow_html=True)
68
 
69
- # πŸ“ˆ Chart Visualization
70
- st.markdown("### πŸ”’ Word Count Breakdown")
71
  p1_len = len(product1.split())
72
  p2_len = len(product2.split())
73
  fig, ax = plt.subplots()
@@ -76,11 +59,12 @@ if st.button("βš”οΈ Compare Now", use_container_width=True):
76
  ax.set_title("Word Count Comparison")
77
  st.pyplot(fig)
78
 
79
- # πŸ“₯ PDF Report
80
  pdf = FPDF()
81
  pdf.add_page()
82
  pdf.set_font("Arial", size=12)
83
  pdf.multi_cell(0, 10, txt="Competitive Analysis Report\n\n" + result)
 
84
  pdf_bytes = pdf.output(dest='S').encode('latin1')
85
  pdf_output = BytesIO(pdf_bytes)
86
 
@@ -88,6 +72,5 @@ if st.button("βš”οΈ Compare Now", use_container_width=True):
88
  label="πŸ“₯ Download PDF Report",
89
  data=pdf_output,
90
  file_name="competitive_analysis_report.pdf",
91
- mime="application/pdf",
92
- use_container_width=True
93
  )
 
7
  from fpdf import FPDF
8
  from io import BytesIO
9
 
10
+ # Set Hugging Face API token from secrets
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
12
 
13
+ # Choose a compatible model (text-generation)
14
  llm = HuggingFaceHub(
15
+ repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
 
16
  )
17
 
18
+ # Prompt template
19
  template = """
20
  Compare the following two products or services:
21
  Product 1:
 
28
  3. Summarize key differentiators between them.
29
  """
30
 
31
+ prompt = PromptTemplate(
32
+ input_variables=["product1", "product2"],
33
+ template=template,
34
+ )
35
+
36
  comparison_chain = LLMChain(llm=llm, prompt=prompt)
37
 
38
+ # Streamlit UI
39
+ st.title("πŸ” Competitive Analysis Tool")
40
+ st.write("Compare two products or services using LLM-powered insights.")
 
 
 
41
 
42
+ product1 = st.text_area("Enter Product/Service 1 Description", height=200)
43
+ product2 = st.text_area("Enter Product/Service 2 Description", height=200)
44
 
45
+ if st.button("Compare"):
 
46
  if not product1 or not product2:
47
  st.warning("Please enter descriptions for both products.")
48
  else:
49
+ result = comparison_chain.run(product1=product1, product2=product2)
50
+ st.subheader("πŸ“Š Comparison Results")
51
+ st.write(result)
 
 
 
52
 
53
+ # Basic chart: Number of keywords in each description (just an example)
 
54
  p1_len = len(product1.split())
55
  p2_len = len(product2.split())
56
  fig, ax = plt.subplots()
 
59
  ax.set_title("Word Count Comparison")
60
  st.pyplot(fig)
61
 
62
+ # Create a downloadable PDF report
63
  pdf = FPDF()
64
  pdf.add_page()
65
  pdf.set_font("Arial", size=12)
66
  pdf.multi_cell(0, 10, txt="Competitive Analysis Report\n\n" + result)
67
+ # Generate PDF content as string and convert to BytesIO
68
  pdf_bytes = pdf.output(dest='S').encode('latin1')
69
  pdf_output = BytesIO(pdf_bytes)
70
 
 
72
  label="πŸ“₯ Download PDF Report",
73
  data=pdf_output,
74
  file_name="competitive_analysis_report.pdf",
75
+ mime="application/pdf"
 
76
  )