heysho commited on
Commit
8f618a4
·
verified ·
1 Parent(s): eaf32d1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ You are an AI assistant specializing in anger management. Your task is to provide thoughtful, practical, and effective advice to help the user manage their anger based on:
21
+ - Who the user is angry at: {who}
22
+ - The specific situation that caused the anger: {content}
23
+
24
+ 1. Acknowledge the user's feelings to validate their emotions.
25
+ 2. Provide practical steps or techniques to manage and reduce their anger.
26
+ 3. Encourage the user to address the underlying issue in a constructive manner.
27
+ 4. Offer additional resources or tips for similar situations in the future.
28
+ """
29
+
30
+ def init_page():
31
+ st.set_page_config(
32
+ page_title="Anger Management - AI Agent Navi",
33
+ page_icon="🧘"
34
+ )
35
+ st.header("Anger Management - AI Agent Navi🧘")
36
+
37
+
38
+ def select_model(temperature=0):
39
+ models = ("GPT-4o","GPT-4o-mini", "Claude 3.5 Sonnet", "Gemini 1.5 Pro")
40
+ model_choice = st.radio("Choose a model:", models)
41
+ if model_choice == "GPT-4o":
42
+ return ChatOpenAI(temperature=temperature, model_name="gpt-4o")
43
+ elif model_choice == "GPT-4o-mini":
44
+ return ChatOpenAI(temperature=temperature, model_name="gpt-4o-mini")
45
+ elif model_choice == "Claude 3.5 Sonnet":
46
+ return ChatAnthropic(temperature=temperature, model_name="claude-3-5-sonnet-20240620")
47
+ elif model_choice == "Gemini 1.5 Pro":
48
+ return ChatGoogleGenerativeAI(temperature=temperature, model="gemini-1.5-pro-latest")
49
+
50
+ def init_chain():
51
+ llm = select_model()
52
+ prompt = ChatPromptTemplate.from_messages([
53
+ ("user", PROMPT),
54
+ ])
55
+ output_parser = StrOutputParser()
56
+ chain = prompt | llm | output_parser
57
+ return chain
58
+
59
+ def main():
60
+ init_page()
61
+ chain = init_chain()
62
+ if chain:
63
+ who = st.text_input("Who are you angry at?", key="who")
64
+ content = st.text_area("What specific situation caused the anger?", key="content")
65
+ if st.button("Submit"):
66
+ result = chain.stream({"who": who, "content": content})
67
+ st.write(result)
68
+
69
+ if __name__ == '__main__':
70
+ main()
71
+
72
+ # Style adjustments (optional, remove if not needed)
73
+ st.markdown(
74
+ """
75
+ <style>
76
+ /* Custom style adjustments */
77
+ .st-emotion-cache-iiif1v { display: none !important; }
78
+ </style>
79
+ """,
80
+ unsafe_allow_html=True,
81
+ )