Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 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 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 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.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|