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""" """ # 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()