File size: 877 Bytes
fa79fa8
 
84c8811
 
fa79fa8
84c8811
 
 
 
 
fa79fa8
41f5877
 
 
 
 
 
7b35252
 
 
 
 
fa79fa8
 
 
 
 
4bb4b5a
fa79fa8
 
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
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')

# Streamlit interface
st.title('Email Classifier')

email_text = st.text_area('Email Text', height=300)

response = openai.chat.completion.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"}
        ]
    )


if st.button('Classify'):
    if email_text:
        st.write(f'The email is classified as: **{response.choices[0].message.content}**')
    else:
        st.write('Please enter some text to classify.')