Update app.py
Browse files5 unmodified lines678910111223 unmodified lines3637383940414243444546474849505152535455565758596061626364656612 unmodified lines798081828384858687888990919293949516 unmodified lines1121131141151161175 unmodified linesimport textwrapimport re# Page settingsst.set_page_config(page_title="Pro Competitive Analysis", layout="centered")st.markdown("""<style>23 unmodified lines</style>""", unsafe_allow_html=True)# App titlest.title("πΌ Competitive Analysis Pro")st.markdown("Generate expert-level comparisons between two products or services with SWOT, business insights, and key differentiators.")# Hugging Face tokenos.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]# Load LLM (chat-style behavior via prompt)llm = HuggingFaceHub(repo_id="meta-llama/Llama-2-13b-chat-hf",model_kwargs={"temperature": 0.7, "max_new_tokens": 1024})# Input fieldsproduct1 = st.text_area("π§© Product/Service 1", height=200, placeholder="e.g., iPhone 13")product2 = st.text_area("π§© Product/Service 2", height=200, placeholder="e.g., iPhone 14")# On generateif st.button("π Run Competitive Analysis", use_container_width=True):if not product1 or not product2:st.warning("Please enter both product descriptions.")else:with st.spinner("π§ Generating insights..."):# Final prompt (no instruction echo)prompt = f"""Compare the following two products or services:12 unmodified linesDo NOT include or mention these instructions.Only return the clean markdown report."""result = llm(prompt)# Display resultst.markdown("### π Expert Comparison")st.markdown(result)# Clean markdown for PDFclean_text = result.replace("**", "").replace("*", "").replace("`", "").replace("#", "").replace("β’", "-")# PDF logicpdf = FPDF()pdf.add_page()pdf.set_font("Arial", size=12)16 unmodified linesexcept Exception:continuepdf_output = BytesIO()pdf.output(pdf_output)pdf_output.seek(0)5 unmodified lines678910111223 unmodified lines363738394041424344454647484950515253545556575859606162636412 unmodified lines7778798081828384858687888990919216 unmodified lines1091101111121131141155 unmodified linesimport textwrapimport re# Page setup + dark themest.set_page_config(page_title="Pro Competitive Analysis", layout="centered")st.markdown("""<style>23 unmodified lines</style>""", unsafe_allow_html=True)# Headerst.title("πΌ Competitive Analysis Pro")st.markdown("Get an expert-level markdown analysis between two products or services, including SWOT, features, and recommendations.")# Set Hugging Face tokenos.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HF_TOKEN"]# Load Mistral LLM (Free model)llm = HuggingFaceHub(repo_id="mistralai/Mistral-7B-Instruct-v0.1",model_kwargs={"temperature": 0.7, "max_new_tokens": 1024})# Inputsproduct1 = st.text_area("π§© Product/Service 1", height=200, placeholder="e.g., iPhone 13")product2 = st.text_area("π§© Product/Service 2", height=200, placeholder="e.g., iPhone 14")# Compareif st.button("π Run Competitive Analysis", use_container_width=True):if not product1 or not product2:st.warning("Please enter both product descriptions.")else:with st.spinner("π§ Generating insights with Mistral..."):prompt = f"""Compare the following two products or services:12 unmodified linesDo NOT include or mention these instructions.Only return the clean markdown report."""result = llm(prompt)# Display outputst.markdown("### π Expert Comparison")st.markdown(result)# Clean markdown textclean_text = result.replace("**", "").replace("*", "").replace("`", "").replace("#", "").replace("β’", "-")# PDF Exportpdf = FPDF()pdf.add_page()pdf.set_font("Arial", size=12)16 unmodified linesexcept Exception:continue# PDF streampdf_output = BytesIO()pdf.output(pdf_output)pdf_output.seek(0)
app.py+13-15