Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
# Load the model and tokenizer
|
5 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
6 |
-
model = AutoModelForCausalLM.from_pretrained("
|
7 |
-
|
8 |
-
# Initialize the text generation pipeline
|
9 |
-
generator = pipeline('text-generation', model="postbot/gpt2-medium-emailgen")
|
10 |
|
11 |
# Streamlit UI styling
|
12 |
-
st.set_page_config(page_title="
|
13 |
|
14 |
-
# Add custom CSS for styling
|
15 |
st.markdown("""
|
16 |
<style>
|
17 |
.title {
|
@@ -43,28 +40,30 @@ st.markdown("""
|
|
43 |
""", unsafe_allow_html=True)
|
44 |
|
45 |
# Title and Header
|
46 |
-
st.markdown('<div class="title">
|
47 |
|
48 |
# User input for email prompt
|
49 |
user_input = st.text_area("Enter the email content prompt:", height=150, key="email_prompt", max_chars=500)
|
50 |
|
51 |
# Add a styled button
|
52 |
-
generate_button = st.button("Generate Email
|
53 |
|
54 |
# Handling the generation
|
55 |
if generate_button:
|
56 |
if user_input:
|
57 |
-
#
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
early_stopping=True,
|
63 |
-
)
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
else:
|
69 |
-
st.error("Please enter a prompt to generate the email
|
|
|
70 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
# Load the model and tokenizer
|
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 {
|
|
|
40 |
""", unsafe_allow_html=True)
|
41 |
|
42 |
# Title and Header
|
43 |
+
st.markdown('<div class="title">Email Generator</div>', unsafe_allow_html=True)
|
44 |
|
45 |
# User input for email prompt
|
46 |
user_input = st.text_area("Enter the email content prompt:", height=150, key="email_prompt", max_chars=500)
|
47 |
|
48 |
# Add a styled button
|
49 |
+
generate_button = st.button("Generate Email", key="generate_button", help="Click to generate email", use_container_width=True)
|
50 |
|
51 |
# Handling the generation
|
52 |
if generate_button:
|
53 |
if user_input:
|
54 |
+
# Tokenize the input
|
55 |
+
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
56 |
+
|
57 |
+
# Generate the email text
|
58 |
+
outputs = model.generate(inputs, max_length=300, num_return_sequences=1, no_repeat_ngram_size=2)
|
|
|
|
|
59 |
|
60 |
+
# Decode and display the result
|
61 |
+
generated_email = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
62 |
+
|
63 |
+
# Display the generated email with some styling
|
64 |
+
st.markdown('<div class="header">Generated Email:</div>', unsafe_allow_html=True)
|
65 |
+
st.markdown(f'<div>{generated_email}</div>', unsafe_allow_html=True)
|
66 |
else:
|
67 |
+
st.error("Please enter a prompt to generate the email.")
|
68 |
+
|
69 |
|