-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_textToEmail.py
61 lines (43 loc) · 1.68 KB
/
streamlit_textToEmail.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
import streamlit as st
from langchain import PromptTemplate
from langchain_openai import OpenAI
template = """
Below is an email that may be poorly worded.
Your goal is to:
- Properly format the email
Please start the email with a warm introduction. Add the introduction if you need to.
Below is the email:
EMAIL: {email}
RESPONSE:
"""
prompt = PromptTemplate(
input_variables=["email"],
template=template,
)
def load_LLM(openai_api_key):
llm = OpenAI(temperature=.7, openai_api_key=openai_api_key)
return llm
st.set_page_config(page_title="Convert Text to Email")
st.markdown("## Enter Your Email To Convert")
def get_api_key():
#input_text = st.text_input(label="OpenAI API Key ", placeholder="Ex: sk-2twmA8tfCb8un4...", key="openai_api_key_input")
input_text = st.text_input(label="OpenAI API Key ", type="password", key="openai_api_key_input")
return input_text
openai_api_key = get_api_key()
def get_text():
input_text = st.text_area(label="Type here", placeholder="Your Email...", key="email_input")
return input_text
email_input = get_text()
if len(email_input.split(" ")) > 700:
st.write("Please enter a shorter email up to a max of 700 words")
st.stop()
st.markdown("### Here is your Drafted Email:")
if email_input:
if not openai_api_key:
st.warning('Enter your OpenAI API Key.)', icon="🔥")
st.stop()
llm = load_LLM(openai_api_key=openai_api_key)
#prompt_with_email = prompt.format(tone=option_tone, dialect=option_dialect, email=email_input)
prompt_with_email = prompt.format(email=email_input)
formatted_email = llm(prompt_with_email)
st.write(formatted_email)