Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import traceback | |
import backend | |
from lib.common.database_support import save_email_to_excel | |
import time | |
def render_gen_email(): | |
try: | |
st.title("Generate Email") | |
excel_file = st.session_state.get("excel_file", "Error Not Found") | |
if excel_file == "Error Not Found": | |
raise Exception("Error Not Found") | |
if not st.session_state.get("user_id"): | |
st.warning("Please fill in your profile information first.") | |
return | |
split_screen_col1, split_screen_col2 = st.columns(2) | |
# Input fields | |
with split_screen_col1: | |
industry_col, recipient_col = st.columns(2) | |
with industry_col: | |
industry = st.text_input("Industry") | |
with recipient_col: | |
role = st.text_input("Role") | |
details_col1, details_col2 = st.columns(2) | |
with details_col1: | |
sender_name = st.text_input("Senders Name") | |
with details_col2: | |
rec_name = st.text_input("Receivers Name") | |
rec_designation = st.text_input("Receivers Designation") | |
rec_company_name = st.text_input("Receivers Company Name") | |
sender_details = { | |
"sender_name": sender_name, | |
} | |
rec_details = { | |
"rec_name": rec_name, | |
"rec_designation": rec_designation, | |
"rec_company_name": rec_company_name | |
} | |
tone = st.selectbox("Tone", ["Formal", "Casual", "Friendly", "Professional"]) | |
context = st.text_area("Context") | |
is_generate_clicked = st.button("Generate Email") | |
with split_screen_col2: | |
if is_generate_clicked: | |
generated_email = backend.collect_context_for_email(industry, role, tone, context, sender_details,rec_details ) | |
st.session_state.generated_email = generated_email | |
st.text_area("Generated Email", value=generated_email, height=300, key="editable_email") | |
st.session_state.is_generate_clicked = True | |
else: | |
st.text_area("Generated Email", height=300, disabled=True) | |
# Save to templates button | |
if st.button("Save to templates"): | |
if st.session_state.get("generated_email"): | |
edited_email = st.session_state.editable_email | |
timestamp = int(time.time()) | |
new_template = { | |
"Name": f"Generated Email {timestamp}", | |
"Subject": "New Generated Email", | |
"Body": edited_email | |
} | |
st.session_state.new_template = new_template # Store the new template in session state | |
st.session_state.show_new_template = True | |
st.session_state.page = "Template Emails" | |
st.rerun() | |
else: | |
st.warning("Please generate an email first.") | |
st.markdown("---") | |
except Exception as err: | |
traceback.print_exc() | |
print(err) | |