Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import traceback
|
2 |
+
import streamlit as st
|
3 |
+
from langchain_core.prompts import ChatPromptTemplate
|
4 |
+
from langchain_core.output_parsers import StrOutputParser
|
5 |
+
from langchain_openai import ChatOpenAI
|
6 |
+
from langchain_anthropic import ChatAnthropic
|
7 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
8 |
+
|
9 |
+
###### dotenv を利用する場合 ######
|
10 |
+
try:
|
11 |
+
from dotenv import load_dotenv
|
12 |
+
load_dotenv()
|
13 |
+
except ImportError:
|
14 |
+
import warnings
|
15 |
+
warnings.warn("dotenv not found. Please make sure to set your environment variables manually.", ImportWarning)
|
16 |
+
################################################
|
17 |
+
|
18 |
+
|
19 |
+
PROMPT = """
|
20 |
+
## 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.
|
21 |
+
## Websites for Review: Please collect reviews from popular platforms like Facebook, Instagram, and other relevant forums based on the product's market presence.
|
22 |
+
## 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.
|
23 |
+
## 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.
|
24 |
+
- Brand: {brand},
|
25 |
+
- Product:{product},
|
26 |
+
- Region: {region}
|
27 |
+
"""
|
28 |
+
|
29 |
+
def init_page():
|
30 |
+
st.set_page_config(
|
31 |
+
page_title="Product Review Checker AI Agent",
|
32 |
+
page_icon="🔍"
|
33 |
+
)
|
34 |
+
st.header("Product Review Checker AI Agent🔍")
|
35 |
+
|
36 |
+
|
37 |
+
def select_model(temperature=0):
|
38 |
+
models = ("GPT-4o","GPT-4o-mini", "Claude 3.5 Sonnet", "Gemini 1.5 Pro")
|
39 |
+
model_choice = st.radio("Choose a model:", models)
|
40 |
+
if model_choice == "GPT-4o":
|
41 |
+
return ChatOpenAI(temperature=temperature, model_name="gpt-4o")
|
42 |
+
elif model_choice == "GPT-4o-mini":
|
43 |
+
return ChatOpenAI(temperature=temperature, model_name="gpt-4o-mini")
|
44 |
+
elif model_choice == "Claude 3.5 Sonnet":
|
45 |
+
return ChatAnthropic(temperature=temperature, model_name="claude-3-5-sonnet-20240620")
|
46 |
+
elif model_choice == "Gemini 1.5 Pro":
|
47 |
+
return ChatGoogleGenerativeAI(temperature=temperature, model="gemini-1.5-pro-latest")
|
48 |
+
|
49 |
+
def init_chain():
|
50 |
+
llm = select_model()
|
51 |
+
prompt = ChatPromptTemplate.from_messages([
|
52 |
+
("user", PROMPT),
|
53 |
+
])
|
54 |
+
output_parser = StrOutputParser()
|
55 |
+
chain = prompt | llm | output_parser
|
56 |
+
return chain
|
57 |
+
|
58 |
+
def main():
|
59 |
+
init_page()
|
60 |
+
chain = init_chain()
|
61 |
+
if chain:
|
62 |
+
brand = st.text_input("Enter the brand name (e.g., Nike)", key="brand")
|
63 |
+
product = st.text_input("Enter the product name (e.g., Air Force One shoes)", key="product")
|
64 |
+
region = st.text_input("Enter your region (e.g., USA)", key="region", value="USA")
|
65 |
+
if st.button("Submit"):
|
66 |
+
result = chain.stream({"brand": brand, "product": product, "region": region})
|
67 |
+
st.write(result)
|
68 |
+
|
69 |
+
|
70 |
+
if __name__ == '__main__':
|
71 |
+
main()
|
72 |
+
|
73 |
+
# Style adjustments (optional, remove if not needed)
|
74 |
+
st.markdown(
|
75 |
+
"""
|
76 |
+
<style>
|
77 |
+
/* Custom style adjustments */
|
78 |
+
.st-emotion-cache-iiif1v { display: none !important; }
|
79 |
+
</style>
|
80 |
+
""",
|
81 |
+
unsafe_allow_html=True,
|
82 |
+
)
|