Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from io import BytesIO
|
|
| 6 |
import textwrap
|
| 7 |
import re
|
| 8 |
|
| 9 |
-
# Page
|
| 10 |
st.set_page_config(page_title="Pro Competitive Analysis", layout="centered")
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
|
@@ -36,31 +36,29 @@ button:hover {
|
|
| 36 |
</style>
|
| 37 |
""", unsafe_allow_html=True)
|
| 38 |
|
| 39 |
-
#
|
| 40 |
st.title("💼 Competitive Analysis Pro")
|
| 41 |
-
st.markdown("
|
| 42 |
|
| 43 |
-
# Hugging Face token
|
| 44 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
|
| 45 |
|
| 46 |
-
# Load LLM (
|
| 47 |
llm = HuggingFaceHub(
|
| 48 |
-
repo_id="
|
| 49 |
model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
|
| 50 |
)
|
| 51 |
|
| 52 |
-
#
|
| 53 |
product1 = st.text_area("🧩 Product/Service 1", height=200, placeholder="e.g., iPhone 13")
|
| 54 |
product2 = st.text_area("🧩 Product/Service 2", height=200, placeholder="e.g., iPhone 14")
|
| 55 |
|
| 56 |
-
#
|
| 57 |
if st.button("🔍 Run Competitive Analysis", use_container_width=True):
|
| 58 |
if not product1 or not product2:
|
| 59 |
st.warning("Please enter both product descriptions.")
|
| 60 |
else:
|
| 61 |
-
with st.spinner("🧠 Generating insights..."):
|
| 62 |
-
|
| 63 |
-
# Final prompt (no instruction echo)
|
| 64 |
prompt = f"""
|
| 65 |
Compare the following two products or services:
|
| 66 |
|
|
@@ -79,17 +77,16 @@ Return a professional analysis in markdown format that includes:
|
|
| 79 |
Do NOT include or mention these instructions.
|
| 80 |
Only return the clean markdown report.
|
| 81 |
"""
|
| 82 |
-
|
| 83 |
result = llm(prompt)
|
| 84 |
|
| 85 |
-
# Display
|
| 86 |
st.markdown("### 📊 Expert Comparison")
|
| 87 |
st.markdown(result)
|
| 88 |
|
| 89 |
-
# Clean markdown
|
| 90 |
clean_text = result.replace("**", "").replace("*", "").replace("`", "").replace("#", "").replace("•", "-")
|
| 91 |
|
| 92 |
-
# PDF
|
| 93 |
pdf = FPDF()
|
| 94 |
pdf.add_page()
|
| 95 |
pdf.set_font("Arial", size=12)
|
|
@@ -112,6 +109,7 @@ Only return the clean markdown report.
|
|
| 112 |
except Exception:
|
| 113 |
continue
|
| 114 |
|
|
|
|
| 115 |
pdf_output = BytesIO()
|
| 116 |
pdf.output(pdf_output)
|
| 117 |
pdf_output.seek(0)
|
|
|
|
| 6 |
import textwrap
|
| 7 |
import re
|
| 8 |
|
| 9 |
+
# Page setup + dark theme
|
| 10 |
st.set_page_config(page_title="Pro Competitive Analysis", layout="centered")
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
|
|
|
| 36 |
</style>
|
| 37 |
""", unsafe_allow_html=True)
|
| 38 |
|
| 39 |
+
# Header
|
| 40 |
st.title("💼 Competitive Analysis Pro")
|
| 41 |
+
st.markdown("Get an expert-level markdown analysis between two products or services, including SWOT, features, and recommendations.")
|
| 42 |
|
| 43 |
+
# Set Hugging Face token
|
| 44 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]
|
| 45 |
|
| 46 |
+
# Load Mistral LLM (Free model)
|
| 47 |
llm = HuggingFaceHub(
|
| 48 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.1",
|
| 49 |
model_kwargs={"temperature": 0.7, "max_new_tokens": 1024}
|
| 50 |
)
|
| 51 |
|
| 52 |
+
# Inputs
|
| 53 |
product1 = st.text_area("🧩 Product/Service 1", height=200, placeholder="e.g., iPhone 13")
|
| 54 |
product2 = st.text_area("🧩 Product/Service 2", height=200, placeholder="e.g., iPhone 14")
|
| 55 |
|
| 56 |
+
# Compare
|
| 57 |
if st.button("🔍 Run Competitive Analysis", use_container_width=True):
|
| 58 |
if not product1 or not product2:
|
| 59 |
st.warning("Please enter both product descriptions.")
|
| 60 |
else:
|
| 61 |
+
with st.spinner("🧠 Generating insights with Mistral..."):
|
|
|
|
|
|
|
| 62 |
prompt = f"""
|
| 63 |
Compare the following two products or services:
|
| 64 |
|
|
|
|
| 77 |
Do NOT include or mention these instructions.
|
| 78 |
Only return the clean markdown report.
|
| 79 |
"""
|
|
|
|
| 80 |
result = llm(prompt)
|
| 81 |
|
| 82 |
+
# Display output
|
| 83 |
st.markdown("### 📊 Expert Comparison")
|
| 84 |
st.markdown(result)
|
| 85 |
|
| 86 |
+
# Clean markdown text
|
| 87 |
clean_text = result.replace("**", "").replace("*", "").replace("`", "").replace("#", "").replace("•", "-")
|
| 88 |
|
| 89 |
+
# PDF Export
|
| 90 |
pdf = FPDF()
|
| 91 |
pdf.add_page()
|
| 92 |
pdf.set_font("Arial", size=12)
|
|
|
|
| 109 |
except Exception:
|
| 110 |
continue
|
| 111 |
|
| 112 |
+
# PDF stream
|
| 113 |
pdf_output = BytesIO()
|
| 114 |
pdf.output(pdf_output)
|
| 115 |
pdf_output.seek(0)
|