Team Ai
Apppublic

AjayKr09/Email_Classification_using_Open_AI

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py31 linesDownload Raw Back to root
1import streamlit as st2import openai3from dotenv import load_dotenv4import os5 6# Load environment variables from .env file7load_dotenv()8 9# Get your OpenAI API key from the environment variables10openai.api_key = os.getenv('OPENAI_API_KEY')11 12# Streamlit interface13st.title('Email Classifier')14 15email_text = st.text_area('Email Text', height=300)16 17response = openai.chat.completion.create(18        model='gpt-3.5-turbo',19        messages=[20            {"role": "system", "content": "You are an email classifier."},21            {"role": "user", "content": f"Classify the following email:\n\n{email_text}\n\nCategories: Spam, Work, Personal, Promotion, Other"}22        ]23    )24 25 26if st.button('Classify'):27    if email_text:28        st.write(f'The email is classified as: **{response.choices[0].message.content}**')29    else:30        st.write('Please enter some text to classify.')31