Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,17 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
| 4 |
# Load the model and tokenizer
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("postbot/gpt2-medium-emailgen")
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("postbot/gpt2-medium-emailgen")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
# Streamlit UI styling
|
| 9 |
-
st.set_page_config(page_title="Email Generator", layout="centered")
|
| 10 |
|
| 11 |
-
# Add
|
| 12 |
st.markdown("""
|
| 13 |
<style>
|
| 14 |
.title {
|
|
@@ -40,28 +43,28 @@ st.markdown("""
|
|
| 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
|
| 50 |
|
| 51 |
# Handling the generation
|
| 52 |
if generate_button:
|
| 53 |
if user_input:
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 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.")
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
|
| 4 |
# Load the model and tokenizer
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("postbot/gpt2-medium-emailgen")
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("postbot/gpt2-medium-emailgen")
|
| 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="ReplyCraft Email Generator", layout="centered")
|
| 13 |
|
| 14 |
+
# Add custom CSS for styling
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
.title {
|
|
|
|
| 43 |
""", unsafe_allow_html=True)
|
| 44 |
|
| 45 |
# Title and Header
|
| 46 |
+
st.markdown('<div class="title">ReplyCraft - Email Reply Generator</div>', unsafe_allow_html=True)
|
| 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 Reply", key="generate_button", help="Click to generate reply", use_container_width=True)
|
| 53 |
|
| 54 |
# Handling the generation
|
| 55 |
if generate_button:
|
| 56 |
if user_input:
|
| 57 |
+
# Generate the reply email
|
| 58 |
+
result = generator(
|
| 59 |
+
user_input,
|
| 60 |
+
max_length=150,
|
| 61 |
+
do_sample=True,
|
| 62 |
+
early_stopping=True,
|
| 63 |
+
)
|
| 64 |
|
| 65 |
+
# Display the generated email reply with styling
|
| 66 |
+
st.markdown('<div class="header">Generated Email Reply:</div>', unsafe_allow_html=True)
|
| 67 |
+
st.markdown(f'<div">{result[0]["generated_text"]}</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 68 |
else:
|
| 69 |
+
st.error("Please enter a prompt to generate the email reply.")
|
| 70 |
+
|