File size: 2,187 Bytes
8e1d66e
34984b3
5a6efbf
6681d84
34984b3
 
c6ae599
3c87d2f
34984b3
3c87d2f
34984b3
3c87d2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64c705a
3c87d2f
 
 
 
34984b3
5a6efbf
6681d84
3c87d2f
8e1d66e
3c87d2f
34984b3
3c87d2f
 
 
6681d84
34984b3
 
 
 
 
6681d84
34984b3
 
 
 
 
 
1f70acc
34984b3
 
c6ae599
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
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("""
    <style>
        .title {
            text-align: center;
            color: #4B0082;
            font-size: 32px;
            font-weight: bold;
        }
        .header {
            text-align: center;
            color: #6A5ACD;
            font-size: 24px;
        }
        .textarea {
            margin-bottom: 20px;
        }
        .button {
            background-color: #6A5ACD;
            color: white;
            font-weight: bold;
            border-radius: 5px;
            padding: 10px 20px;
        }
        .button:hover {
            background-color: #4B0082;
        }

    </style>
""", unsafe_allow_html=True)

# Title and Header
st.markdown('<div class="title">Email Generator</div>', 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('<div class="header">Generated Email:</div>', unsafe_allow_html=True)
        st.markdown(f'<div>{generated_email}</div>', unsafe_allow_html=True)
    else:
        st.error("Please enter a prompt to generate the email.")