Spaces:
Sleeping
Sleeping
File size: 3,032 Bytes
3d67f45 4d39100 3d67f45 |
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 |
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
PROMPT = """
1. Task: Generate a unique motivational or reflective quote that relates directly to the user's reported feeling and plan for the day.
1-1.Ensure the quote is relevant and offers either support or inspiration based on the specific emotional context provided.
1-2.Avoid repeating any quotes, and do not use quotes by Steve Jobs.
1-3.Seek out lesser-known quotes and consider a diverse range of cultural and historical sources to enrich the variety and inclusiveness of the selections.
Provide a brief explanation of why the chosen quote fits the situation described by the user.
2.Feeling: {feeling}.
3.Reason for the feeling: {reason}.
4.Plan for the day: {plan}.
5. Explain within 100 words in English.
"""
def init_page():
st.set_page_config(
page_title="Word of the Day AI Agent",
page_icon="🧘"
)
st.header("Word of the Day 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()
# Style adjustments (optional, remove if not needed)
st.markdown("""<style>.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,)
chain = init_chain()
if chain:
feeling = st.selectbox(
"How are you feeling today?",
("I want to be more motivated", "I'm feeling sad", "I'm angry", "I just want to relax today", "I feel excited", "I'm feeling anxious"),
key="feeling"
)
reason = st.text_input("What's the reason for this feeling?", key="reason")
plan = st.text_input("What's your plan for today?", key="plan")
if st.button("Submit"):
result = chain.stream({"feeling": feeling, "reason": reason, "plan": plan})
st.write(result)
if __name__ == '__main__':
main()
|