GIRI45 commited on
Commit
0226fdb
Β·
verified Β·
1 Parent(s): 20b9098

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.chat_models import ChatOpenAI
3
+ from langchain.prompts import PromptTemplate
4
+ from langchain.chains import LLMChain
5
+ import os
6
+
7
+ # Set your OpenAI key
8
+ openai_api_key = os.getenv("OPENAI_API_KEY")
9
+ os.environ["OPENAI_API_KEY"] = openai_api_key
10
+
11
+ # Prompt template for comparison
12
+ prompt_template = PromptTemplate(
13
+ input_variables=["product1", "product2"],
14
+ template="""
15
+ Compare the following two products/services:
16
+
17
+ Product 1: {product1}
18
+ Product 2: {product2}
19
+
20
+ Please provide the following:
21
+ 1. A feature-by-feature comparison.
22
+ 2. A SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis for each.
23
+ 3. A comparative summary highlighting key differentiators.
24
+ """
25
+ )
26
+
27
+ # Initialize LLM and chain
28
+ llm = ChatOpenAI(temperature=0, model="gpt-4")
29
+ comparison_chain = LLMChain(llm=llm, prompt=prompt_template)
30
+
31
+ # Streamlit UI
32
+ st.set_page_config(page_title="Competitive Analysis Tool", layout="wide")
33
+ st.title("πŸ” Competitive Analysis Tool")
34
+
35
+ st.markdown("Compare two products or services and get a full SWOT analysis and feature comparison.")
36
+
37
+ # Input fields
38
+ product1 = st.text_area("πŸ“ Enter details of Product/Service 1", height=200)
39
+ product2 = st.text_area("πŸ“ Enter details of Product/Service 2", height=200)
40
+
41
+ # Button
42
+ if st.button("Compare"):
43
+ if product1.strip() and product2.strip():
44
+ with st.spinner("Generating analysis..."):
45
+ result = comparison_chain.run(product1=product1, product2=product2)
46
+
47
+ # Display result in separate sections
48
+ st.subheader("πŸ“Š Feature Comparison & SWOT Analysis")
49
+ st.markdown(result)
50
+ else:
51
+ st.warning("Please enter details for both products/services.")
52
+
53
+ # Footer
54
+ st.markdown("---")
55
+ st.caption("Powered by OpenAI + Langchain + Streamlit")