-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamehobbyhaiku.py
74 lines (63 loc) · 1.79 KB
/
namehobbyhaiku.py
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
#demo
import streamlit as st
import cohere
import os
api_key = os.environ.get('CO_API_KEY')
co = cohere.Client(api_key)
def generate_haiku(name,hobby):
"""Generate a haiku given the name and hobby provided as inputs
Arguments: name (str)
hobby (str)
Returns:
HAIKU: a haiku given the name and hobby inputs (str)
"""
prompt = f"""Generate a haiku using the provided NAME and HOBBY. Here are a few examples.
NAME: Squidward
HOBBY: playing the clarinet
HAIKU: Squidward's heart in tune,
Clarinet whispers the sea,
Notes of longing croon.
--
NAME: Bruno
HOBBY: making zippers
HAIKU:Bruno's nimble hands,
Zippers dance at his command,
Seamless art expands.
--
NAME: Roy
HOBBY: flame alchemy
HAIKU: Flames in Roy's control,
Alchemy's fierce, burning soul,
Inferno takes its toll.
--
NAME: Joey
HOBBY: backpacking through Western Europe
HAIKU:Joey roams the West,
Backpack and dreams manifest,
Europe's heart, his quest.
NAME: {name}
HOBBY: {hobby}
HAIKU:
"""
# Call the Cohere Generate endpoint
response = co.generate(
model="command-nightly",
prompt=prompt,
max_tokens=50,
temperature=0.7,
k=0,
stop_sequences=["--"],
)
HAIKU = response.generations[0].text
HAIKU = HAIKU.replace("\n\n--", "").replace("\n--", "").strip()
return HAIKU
def run():
st.title("NAME👋 HOBBY🫶 HAIKU GENERATOR")
name = st.text_input("Name:", placeholder="Squidward")
hobby = st.text_input("Hobby:", placeholder = "Playing the clarinet")
if st.button("Generate"):
if name and hobby:
HAIKU = generate_haiku(name,hobby)
st.write(HAIKU.replace("\n","\n\n"))
if __name__ == "__main__":
run()