import streamlit as st import openai from dotenv import load_dotenv import os # Load environment variables from .env file load_dotenv() # Get your OpenAI API key from the environment variables openai.api_key = os.getenv('OPENAI_API_KEY') # Function to classify email def classify_email(email_text): response = openai.ChatCompletion.create( model='gpt-3.5-turbo', messages=[ {"role": "system", "content": "You are an email classifier."}, {"role": "user", "content": f"Classify the following email:\n\n{email_text}\n\nCategories: Spam, Work, Personal, Promotion, Other"} ] ) return response['choices'][0]['message']['content'].strip() # Streamlit interface st.title('Email Classifier') st.write('Enter the email text below and click "Classify" to determine its category.') email_text = st.text_area('Email Text', height=300) if st.button('Classify'): if email_text: category = classify_email(email_text) st.write(f'The email is classified as: **{category}**') else: st.write('Please enter some text to classify.')