Spaces:
Sleeping
Sleeping
File size: 4,130 Bytes
9b93e00 840482f 9b93e00 840482f 9b93e00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
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()
|