Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,14 +5,57 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("sagorsarker/emailgenerator")
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("sagorsarker/emailgenerator")
|
| 7 |
|
| 8 |
-
# Streamlit UI
|
| 9 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# User input for email prompt
|
| 12 |
-
user_input = st.text_area("Enter the email content prompt:")
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
if user_input:
|
| 17 |
# Tokenize the input
|
| 18 |
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
|
@@ -22,7 +65,9 @@ if st.button("Generate Email"):
|
|
| 22 |
|
| 23 |
# Decode and display the result
|
| 24 |
generated_email = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
else:
|
| 28 |
st.error("Please enter a prompt to generate the email.")
|
|
|
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("sagorsarker/emailgenerator")
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("sagorsarker/emailgenerator")
|
| 7 |
|
| 8 |
+
# Streamlit UI styling
|
| 9 |
+
st.set_page_config(page_title="Email Generator", layout="centered")
|
| 10 |
+
|
| 11 |
+
# Add some custom CSS for styling
|
| 12 |
+
st.markdown("""
|
| 13 |
+
<style>
|
| 14 |
+
.title {
|
| 15 |
+
text-align: center;
|
| 16 |
+
color: #4B0082;
|
| 17 |
+
font-size: 32px;
|
| 18 |
+
font-weight: bold;
|
| 19 |
+
}
|
| 20 |
+
.header {
|
| 21 |
+
text-align: center;
|
| 22 |
+
color: #6A5ACD;
|
| 23 |
+
font-size: 24px;
|
| 24 |
+
}
|
| 25 |
+
.textarea {
|
| 26 |
+
margin-bottom: 20px;
|
| 27 |
+
}
|
| 28 |
+
.button {
|
| 29 |
+
background-color: #6A5ACD;
|
| 30 |
+
color: white;
|
| 31 |
+
font-weight: bold;
|
| 32 |
+
border-radius: 5px;
|
| 33 |
+
padding: 10px 20px;
|
| 34 |
+
}
|
| 35 |
+
.button:hover {
|
| 36 |
+
background-color: #4B0082;
|
| 37 |
+
}
|
| 38 |
+
.generated-email {
|
| 39 |
+
background-color: #f4f4f4;
|
| 40 |
+
padding: 15px;
|
| 41 |
+
border-radius: 10px;
|
| 42 |
+
border: 1px solid #ddd;
|
| 43 |
+
font-family: 'Courier New', Courier, monospace;
|
| 44 |
+
}
|
| 45 |
+
</style>
|
| 46 |
+
""", unsafe_allow_html=True)
|
| 47 |
+
|
| 48 |
+
# Title and Header
|
| 49 |
+
st.markdown('<div class="title">Email Generator</div>', unsafe_allow_html=True)
|
| 50 |
|
| 51 |
# User input for email prompt
|
| 52 |
+
user_input = st.text_area("Enter the email content prompt:", height=150, key="email_prompt", max_chars=500)
|
| 53 |
|
| 54 |
+
# Add a styled button
|
| 55 |
+
generate_button = st.button("Generate Email", key="generate_button", help="Click to generate email", use_container_width=True)
|
| 56 |
+
|
| 57 |
+
# Handling the generation
|
| 58 |
+
if generate_button:
|
| 59 |
if user_input:
|
| 60 |
# Tokenize the input
|
| 61 |
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
|
|
|
| 65 |
|
| 66 |
# Decode and display the result
|
| 67 |
generated_email = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 68 |
+
|
| 69 |
+
# Display the generated email with some styling
|
| 70 |
+
st.markdown('<div class="header">Generated Email:</div>', unsafe_allow_html=True)
|
| 71 |
+
st.markdown(f'<div class="generated-email">{generated_email}</div>', unsafe_allow_html=True)
|
| 72 |
else:
|
| 73 |
st.error("Please enter a prompt to generate the email.")
|