heysho commited on
Commit
cd5d489
·
verified ·
1 Parent(s): 794c43b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -65
app.py CHANGED
@@ -13,71 +13,62 @@ st.title('Rap Generator')
13
 
14
 
15
 
16
- # Initialize the session state for 'authenticated' key
17
- if 'authenticated' not in st.session_state:
18
- st.session_state['authenticated'] = False
19
-
20
  if 'usage_count' not in st.session_state:
21
  st.session_state['usage_count'] = 0 # Usage counter
22
 
23
- password_key = st.secrets['PASSWORD']
24
-
25
-
26
-
27
- # If authenticated, show the main page content
28
- if st.session_state['authenticated']:
29
- # Define a maximum number of uses
30
- max_uses = 3
31
-
32
- if st.session_state['usage_count'] < max_uses:
33
- # Main Contents Start from here -------------------------------
34
-
35
- st.subheader('English')
36
- en_input_topic = st.text_input("Topic(e.g. Sunday)", key="en_input_topic")
37
- en_input_occupation = st.text_input("Your Occupation(e.g. Data Scientist)", key="en_input_occupation")
38
- en_input_message = st.text_input("What do you want to say? (e.g. prepare for tomorrow)", key="en_input_message")
39
-
40
- if st.button("Generate a rap", key="en_generate_rap"):
41
- # Create a prompt based on the user input
42
- en_prompt = f"""
43
- - Task: Generate a rap in English
44
- - Length: a rap with 8 lines, each line having 8 beats.
45
- - Topic:{en_input_topic}。
46
- - Occupation: {en_input_occupation}。
47
- - What you want to say: {en_input_message}
48
- """
49
- # Make a request to the API to generate text
50
- en_response = openai.ChatCompletion.create(
51
- model=ai_model, # Use the engine of your choice
52
- messages=[{"role": "user", "content": en_prompt}],
53
- max_tokens=token
54
- )
55
- st.write(en_response["choices"][0]["message"]["content"])
56
-
57
- st.text(" ")
58
- st.text(" ")
59
-
60
-
61
- st.subheader('日本語')
62
- ja_input_topic = st.text_input("トピック(例:日曜日)", key="ja_input_topic")
63
- ja_input_occupation = st.text_input("あなたの仕事(例:データサイエンティスト)", key="ja_input_occupation")
64
- ja_input_message = st.text_input("言いたいこと(例:明日に向けて気持ちを準備したい)", key="ja_input_message")
65
-
66
- if st.button("Generate a rap", key="ja_generate_rap"):
67
- # Create a prompt based on the user input
68
- ja_prompt = f"""
69
- - Task: Generate a rap in Japanese
70
- - Length: a rap with 8 lines, each line having 8 beats.
71
- - Topic:{ja_input_topic}。
72
- - Occupation: {ja_input_occupation}。
73
- - What you want to say: {ja_input_message}
74
- """
75
- # Make a request to the API to generate text
76
- ja_response = openai.ChatCompletion.create(
77
- model=ai_model, # Use the engine of your choice
78
- messages=[{"role": "user", "content": ja_prompt}],
79
- max_tokens=token
80
- )
81
- st.write(ja_response["choices"][0]["message"]["content"])
82
- else:
83
- st.error("You have reached your maximum usage limit.")
 
13
 
14
 
15
 
 
 
 
 
16
  if 'usage_count' not in st.session_state:
17
  st.session_state['usage_count'] = 0 # Usage counter
18
 
19
+
20
+
21
+ max_uses = 3
22
+
23
+ if st.session_state['usage_count'] < max_uses:
24
+ # Main Contents Start from here -------------------------------
25
+
26
+ st.subheader('English')
27
+ en_input_topic = st.text_input("Topic(e.g. Sunday)", key="en_input_topic")
28
+ en_input_occupation = st.text_input("Your Occupation(e.g. Data Scientist)", key="en_input_occupation")
29
+ en_input_message = st.text_input("What do you want to say? (e.g. prepare for tomorrow)", key="en_input_message")
30
+
31
+ if st.button("Generate a rap", key="en_generate_rap"):
32
+ # Create a prompt based on the user input
33
+ en_prompt = f"""
34
+ - Task: Generate a rap in English
35
+ - Length: a rap with 8 lines, each line having 8 beats.
36
+ - Topic:{en_input_topic}。
37
+ - Occupation: {en_input_occupation}。
38
+ - What you want to say: {en_input_message}。
39
+ """
40
+ # Make a request to the API to generate text
41
+ en_response = openai.ChatCompletion.create(
42
+ model=ai_model, # Use the engine of your choice
43
+ messages=[{"role": "user", "content": en_prompt}],
44
+ max_tokens=token
45
+ )
46
+ st.write(en_response["choices"][0]["message"]["content"])
47
+
48
+ st.text(" ")
49
+ st.text(" ")
50
+
51
+
52
+ st.subheader('日本語')
53
+ ja_input_topic = st.text_input("トピック(例:日曜日)", key="ja_input_topic")
54
+ ja_input_occupation = st.text_input("あなたの仕事(例:データサイエンティスト)", key="ja_input_occupation")
55
+ ja_input_message = st.text_input("言いたいこと(例:明日に向けて気持ちを準備したい)", key="ja_input_message")
56
+
57
+ if st.button("Generate a rap", key="ja_generate_rap"):
58
+ # Create a prompt based on the user input
59
+ ja_prompt = f"""
60
+ - Task: Generate a rap in Japanese
61
+ - Length: a rap with 8 lines, each line having 8 beats.
62
+ - Topic:{ja_input_topic}。
63
+ - Occupation: {ja_input_occupation}。
64
+ - What you want to say: {ja_input_message}。
65
+ """
66
+ # Make a request to the API to generate text
67
+ ja_response = openai.ChatCompletion.create(
68
+ model=ai_model, # Use the engine of your choice
69
+ messages=[{"role": "user", "content": ja_prompt}],
70
+ max_tokens=token
71
+ )
72
+ st.write(ja_response["choices"][0]["message"]["content"])
73
+ else:
74
+ st.error("You have reached your maximum usage limit.")