Delete app.py
Browse files
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 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|