Spaces:
Build error
Build error
Adding parameters
Browse files
app.py
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
|
4 |
-
EXAMPLES = [
|
5 |
-
"Write a professional email to the customers of a telco company offering 100 minutes free if they buy 1000 minutes",
|
6 |
-
"Write a formal email to the customers of a bank offering a new home insurance",
|
7 |
-
"Write an informal email to the customers of a bank, offering a new car insurance, using emojis in the subject",
|
8 |
-
]
|
9 |
-
|
10 |
openai.api_key = st.secrets["openai-api-key"]
|
11 |
|
12 |
|
@@ -28,38 +22,50 @@ def generate_email(prompt: str, max_tokens: int = 256) -> str:
|
|
28 |
return message
|
29 |
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
st.
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
label="Examples",
|
40 |
-
options=EXAMPLES,
|
41 |
-
on_change=example_selected,
|
42 |
-
key="selected_example"
|
43 |
-
)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
)
|
57 |
|
58 |
-
with st.form(key="form"):
|
59 |
-
submit_button = st.form_submit_button(label='Generate email', disabled=len(st.session_state["prompt"]) == 0)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
output = generate_email(prompt_input, max_tokens=max_tokens_input)
|
64 |
-
st.markdown("----")
|
65 |
-
st.markdown(output)
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
openai.api_key = st.secrets["openai-api-key"]
|
5 |
|
6 |
|
|
|
22 |
return message
|
23 |
|
24 |
|
25 |
+
TEMPLATE = "Write a {tone} email to the customers of a {company_type} offering {offer}"
|
26 |
+
|
27 |
+
|
28 |
+
def main():
|
29 |
+
st.title("Email Generator")
|
30 |
+
st.text("by Marc Puig")
|
31 |
+
|
32 |
+
st.sidebar.markdown("### :arrow_right: Parameters")
|
33 |
+
|
34 |
+
email_tone = st.sidebar.selectbox(
|
35 |
+
label="tone",
|
36 |
+
options=("serious", "funny", "formal"),
|
37 |
+
)
|
38 |
|
39 |
+
email_company_type = st.sidebar.selectbox(
|
40 |
+
label="Company type",
|
41 |
+
options=("telco company", "bank", "insurance")
|
42 |
+
)
|
43 |
|
44 |
+
offer = st.sidebar.text_area(
|
45 |
+
label="offer description",
|
46 |
+
value="100 minutes free if they buy 1000 minutes"
|
47 |
+
)
|
48 |
|
49 |
+
prompt_input = "lorem ipsum"
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
if email_tone and email_company_type and offer:
|
52 |
+
prompt_input = TEMPLATE.format(tone=email_tone, company_type=email_company_type, offer=offer)
|
53 |
+
|
54 |
+
max_tokens_input = st.slider(
|
55 |
+
label="How many characters do you want your email to be? ",
|
56 |
+
help="A typical email is usually 100-500 characters",
|
57 |
+
min_value=64,
|
58 |
+
max_value=750,
|
59 |
+
value=200
|
60 |
+
)
|
61 |
|
62 |
+
with st.form(key="form"):
|
63 |
+
if st.form_submit_button(label='Generate email', disabled=len(prompt_input) == 0):
|
64 |
+
with st.spinner("Generating email..."):
|
65 |
+
output = generate_email(prompt_input, max_tokens=max_tokens_input)
|
66 |
+
st.markdown("----")
|
67 |
+
st.markdown(output)
|
|
|
68 |
|
|
|
|
|
69 |
|
70 |
+
if __name__ == "__main__":
|
71 |
+
main()
|
|
|
|
|
|