import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("sagorsarker/emailgenerator")
model = AutoModelForCausalLM.from_pretrained("sagorsarker/emailgenerator")
# Streamlit UI styling
st.set_page_config(page_title="Email Generator", layout="centered")
# Add some custom CSS for styling
st.markdown("""
""", unsafe_allow_html=True)
# Title and Header
st.markdown('
Email Generator
', unsafe_allow_html=True)
# User input for email prompt
user_input = st.text_area("Enter the email content prompt:", height=150, key="email_prompt", max_chars=500)
# Add a styled button
generate_button = st.button("Generate Email", key="generate_button", help="Click to generate email", use_container_width=True)
# Handling the generation
if generate_button:
if user_input:
# Tokenize the input
inputs = tokenizer.encode(user_input, return_tensors="pt")
# Generate the email text
outputs = model.generate(inputs, max_length=300, num_return_sequences=1, no_repeat_ngram_size=2)
# Decode and display the result
generated_email = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Display the generated email with some styling
st.markdown('', unsafe_allow_html=True)
st.markdown(f'{generated_email}
', unsafe_allow_html=True)
else:
st.error("Please enter a prompt to generate the email.")