AsthanM commited on
Commit
bb376ec
Β·
verified Β·
1 Parent(s): 5dcca64

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -93
app.py DELETED
@@ -1,93 +0,0 @@
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
-
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:
36
- {product1}
37
- Product 2:
38
- {product2}
39
- Instructions:
40
- 1. Provide a feature-by-feature comparison.
41
- 2. Generate a SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis for each.
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()
74
- ax.bar(["Product 1", "Product 2"], [p1_len, p2_len], color=["skyblue", "salmon"])
75
- ax.set_ylabel("Word Count")
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
-
87
- st.download_button(
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
- )