heysho commited on
Commit
c34d5e5
1 Parent(s): bee169c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -0
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ ai_model = "gpt-4-turbo"
5
+ token = 4096
6
+
7
+ # Set the page title and favicon
8
+ st.set_page_config(page_title="Daily Reminder", page_icon=":bar_chart:")
9
+
10
+ openai.api_key = st.secrets['OPENAI_API_KEY']
11
+ st.title('Daily Reminder')
12
+
13
+
14
+
15
+
16
+
17
+
18
+ if 'usage_count' not in st.session_state:
19
+ st.session_state['usage_count'] = 0 # Usage counter
20
+
21
+
22
+
23
+ max_uses = 3
24
+
25
+ if st.session_state['usage_count'] < max_uses:
26
+ # Main Contents Start from here -------------------------------
27
+
28
+ st.subheader('English')
29
+ en_input_topic = st.selectbox(
30
+ "How are you feeling today?",
31
+ ("I want to be more motivated", "I'm feeling sad", "I'm angry", "I just want to relax today"),
32
+ index=0, # Setting a default index if desired, or use None for no default selection
33
+ key="en_input_topic"
34
+ )
35
+
36
+ en_input_reason = st.text_input(
37
+ "What's the reason for this feeling? (e.g., 'I lost my motivation')",
38
+ key="en_input_reason"
39
+ )
40
+
41
+ en_input_plan = st.text_input(
42
+ "What's your plan for today? (e.g., 'I'm going to meet my friends.')",
43
+ key="en_input_plan"
44
+ )
45
+
46
+ if st.button("Generate a daily reminder", key="en_generate_quote"):
47
+ # Create a prompt based on the user input
48
+ en_prompt = f"""
49
+ - Task: Select a unique quote each time and explain its relevance to the situation described.
50
+ Avoid repeating quotes and do not use quotes by Steve Jobs.
51
+ - Feeling: {en_input_topic}.
52
+ - Reason for the feeling: {en_input_reason}.
53
+ - Plan for the day: {en_input_plan}.
54
+ - Guidelines: Aim for quotes that are less commonly cited or consider a variety of cultural or historical sources to enhance diversity in selections.
55
+ """
56
+ # Make a request to the API to generate text
57
+ en_response = openai.ChatCompletion.create(
58
+ model=ai_model, # Use the engine of your choice
59
+ messages=[{"role": "user", "content": en_prompt}],
60
+ max_tokens=token
61
+ )
62
+ st.write(en_response["choices"][0]["message"]["content"])
63
+
64
+ st.text(" ")
65
+ st.text(" ")
66
+
67
+
68
+ st.subheader('日本語')
69
+ ja_input_topic = st.selectbox(
70
+ "今日の気分を教えてください?",
71
+ ("モチベーションを上げたい", "悲しい", "怒っている", "今はリラックスしたい"),
72
+ index=0, # Setting a default index if desired, or use None for no default selection
73
+ key="ja_input_topic"
74
+ )
75
+
76
+ ja_input_reason = st.text_input(
77
+ "その理由は何ですか?(例:「モチベーションが上がらない」)",
78
+ key="ja_input_reason"
79
+ )
80
+
81
+ ja_input_plan = st.text_input(
82
+ "今日の予定は何ですか?(例:「友達と会う予定です」)",
83
+ key="ja_input_plan"
84
+ )
85
+
86
+ if st.button("今日の名言を生成する", key="ja_generate_quote"):
87
+ # Create a prompt based on the user input
88
+ ja_prompt = f"""
89
+ - Task: Select a unique quote each time and explain its relevance to the situation described in Japanese language.
90
+ Avoid repeating quotes and do not use quotes by Steve Jobs.
91
+ - Feeling: {ja_input_topic}.
92
+ - Reason for the feeling: {ja_input_reason}.
93
+ - Plan for the day: {ja_input_plan}.
94
+ - Guidelines: Aim for quotes that are less commonly cited or consider a variety of cultural or historical sources to enhance diversity in selections.
95
+ """
96
+ # Make a request to the API to generate text
97
+ ja_response = openai.ChatCompletion.create(
98
+ model=ai_model, # Use the engine of your choice
99
+ messages=[{"role": "user", "content": ja_prompt}],
100
+ max_tokens=token
101
+ )
102
+ st.write(ja_response["choices"][0]["message"]["content"])
103
+ else:
104
+ st.error("You have reached your maximum usage limit.")