draftlytics / app.py
sab
first commit
840482f
import os
import openai
import streamlit as st
from utils.mail_generator import AzureOpenAIEmailGenerator
# Configurazione e costanti
class Config:
PAGE_TITLE = "Draftlytics πŸ“§"
PAGE_ICON = "πŸ“¬"
HEADER_COLOR = "#9d03fc"
ENGINE = "gpt-4"
CUSTOM_CSS = f"""
<style>
.css-1egvi7u {{ margin-top: -4rem; }} /* Move app further up and remove top padding */
.css-znku1x a {{ color: {HEADER_COLOR}; }} /* Change hyperlink href link color */
.css-qrbaxs {{ min-height: 0.0rem; }} /* Change height of text input fields headers */
.stSpinner > div > div {{ border-top-color: {HEADER_COLOR}; }} /* Change spinner color to primary color */
.css-15tx938 {{ min-height: 0.0rem; }} /* Change min height of text input box */
header {{ visibility: hidden; }} /* Hide top header line */
#MainMenu {{ visibility: hidden; }} /* Hide "made with streamlit" footer menu area */
footer {{ visibility: hidden; }} /* Hide footer */
</style>
"""
# Classe principale dell'applicazione
class DraftlyticsApp:
def __init__(self):
self.email_generator = AzureOpenAIEmailGenerator(Config.ENGINE)
self.email_text = ""
def set_page_config(self):
st.set_page_config(page_title=Config.PAGE_TITLE, page_icon=Config.PAGE_ICON)
def apply_custom_css(self):
st.markdown(Config.CUSTOM_CSS, unsafe_allow_html=True)
def display_header(self):
#st.image('images/rephraise_logo.png', width=100)
st.markdown(f"# Welcome to {Config.PAGE_TITLE} πŸ€–")
st.write("### Your Expert AI Email Assistant ")
def get_user_input(self):
st.subheader("πŸ“Œ What is the main subject of your email?")
with st.expander("βœ‰οΈ Email Input", expanded=True):
input_c1 = st.text_input('Provide the main topic of your email', '')
input_c2 = st.text_input('Provide the secondary topic of your email (optional)', '')
col1, col2, col3, space, col4 = st.columns([5, 5, 5, 0.5, 5])
with col1:
input_sender = st.text_input('Sender Name', '')
with col2:
input_recipient = st.text_input('Recipient Name', '')
with col3:
input_style = st.selectbox('Writing Style', ('formal', 'motivated', 'concerned', 'disappointed'),
index=0)
with col4:
st.write("\n") # add spacing
st.write("\n") # add spacing
if st.button('Generate Email πŸš€'):
with st.spinner('Generating your email... ⏳'):
self.validate_and_generate_email(input_c1, input_c2, input_sender, input_recipient, input_style)
st.write("Note: The generated email will be in English.")
def validate_and_generate_email(self, input_c1, input_c2, input_sender, input_recipient, input_style):
if not input_c1.strip():
st.error('⚠️ The main topic is required!')
return
if not input_sender.strip():
st.error('⚠️ The sender name is required!')
return
if not input_recipient.strip():
st.error('⚠️ The recipient name is required!')
return
input_contents = [input_c1.strip()]
if input_c2.strip():
input_contents.append(input_c2.strip())
self.email_text = self.email_generator.generate_mail_format(
input_sender.strip(), input_recipient.strip(), input_style, input_contents
)
self.display_email()
@st.dialog("πŸ“§ RESULT:")
def display_email(self):
if self.email_text:
st.write('\n') # add spacing
st.markdown(self.email_text)
def run(self):
self.set_page_config()
self.apply_custom_css()
self.display_header()
self.get_user_input()
# Funzione principale per eseguire l'applicazione
def main():
app = DraftlyticsApp()
app.run()
if __name__ == '__main__':
main()