File size: 3,442 Bytes
d3de98c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97e4e1a
 
 
 
 
 
d3de98c
 
 
97e4e1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import traceback
import streamlit as st
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
from langchain_google_genai import ChatGoogleGenerativeAI

###### dotenv γ‚’εˆ©η”¨γ™γ‚‹ε ΄εˆ ######
try:
    from dotenv import load_dotenv
    load_dotenv()
except ImportError:
    import warnings
    warnings.warn("dotenv not found. Please make sure to set your environment variables manually.", ImportWarning)
################################################


PROMPT = """
## Task: Analyze customer reviews for our product, the 'Review Analyzer'. Focus on extracting key points that a potential buyer would find helpful. Include sentiment analysis to determine overall customer satisfaction.
## Websites for Review: Please collect reviews from popular platforms like Facebook, Instagram, and other relevant forums based on the product's market presence.
## Objective: The goal is to provide potential customers with a clear and concise summary of what current users think about the product. Highlight the most praised features, common issues, and general sentiment.
## Additional: Summarize the analysis in about 200 words, indicating the sources of the reviews and the number of posts analyzed. Ensure the summary is straightforward and easy to understand, tailored to assist in making purchasing decisions.
- Brand: {brand},
- Product:{product},
- Region: {region}
"""

def init_page():
    st.set_page_config(
        page_title="Product Review Checker AI Agent",
        page_icon="πŸ”"
    )
    st.header("Product Review Checker AI AgentπŸ”")


def select_model(temperature=0):
    models = ("GPT-4o","GPT-4o-mini", "Claude 3.5 Sonnet", "Gemini 1.5 Pro")
    model_choice = st.radio("Choose a model:", models)
    if model_choice == "GPT-4o":
        return ChatOpenAI(temperature=temperature, model_name="gpt-4o")
    elif model_choice == "GPT-4o-mini":
        return ChatOpenAI(temperature=temperature, model_name="gpt-4o-mini")
    elif model_choice == "Claude 3.5 Sonnet":
        return ChatAnthropic(temperature=temperature, model_name="claude-3-5-sonnet-20240620")
    elif model_choice == "Gemini 1.5 Pro":
        return ChatGoogleGenerativeAI(temperature=temperature, model="gemini-1.5-pro-latest")

def init_chain():
    llm = select_model()
    prompt = ChatPromptTemplate.from_messages([
        ("user", PROMPT),
    ])
    output_parser = StrOutputParser()
    chain = prompt | llm | output_parser
    return chain

def main():
    init_page()
    chain = init_chain()
    if chain:
        brand = st.text_input("Enter the brand name (e.g., Nike)", key="brand")
        product = st.text_input("Enter the product name (e.g., Air Force One shoes)", key="product")
        region = st.text_input("Enter your region (e.g., USA)", key="region", value="USA")
        if st.button("Submit"):
            result = chain.stream({"brand": brand, "product": product, "region": region})
            st.write(result)   
      

if __name__ == '__main__':
    main()

# Style adjustments (optional, remove if not needed)
st.markdown(
"""
<style>
/* Custom style adjustments */
.st-emotion-cache-15ecox0 { display: none !important; }
@media (max-width: 50.5rem) {
    .st-emotion-cache-13ln4jf {
        max-width: calc(0rem + 100vw);
    }
}
</style>
""",
    unsafe_allow_html=True,
)