Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import openai
|
| 3 |
+
|
| 4 |
+
# Set your OpenAI API key
|
| 5 |
+
openai.api_key = 'your_openai_api_key'
|
| 6 |
+
|
| 7 |
+
# Function to classify email
|
| 8 |
+
def classify_email(email_text):
|
| 9 |
+
response = openai.Completion.create(
|
| 10 |
+
model='gpt-3.5-turbo-instruct',
|
| 11 |
+
prompt=f'Classify the following email:\n\n{email_text}\n\nCategories: Spam, Work, Personal, Promotion, Other',
|
| 12 |
+
max_tokens=50
|
| 13 |
+
)
|
| 14 |
+
return response.choices[0].text.strip()
|
| 15 |
+
|
| 16 |
+
# Streamlit interface
|
| 17 |
+
st.title('Email Classifier')
|
| 18 |
+
st.write('Enter the email text below and click "Classify" to determine its category.')
|
| 19 |
+
|
| 20 |
+
email_text = st.text_area('Email Text', height=300)
|
| 21 |
+
|
| 22 |
+
if st.button('Classify'):
|
| 23 |
+
if email_text:
|
| 24 |
+
category = classify_email(email_text)
|
| 25 |
+
st.write(f'The email is classified as: **{category}**')
|
| 26 |
+
else:
|
| 27 |
+
st.write('Please enter some text to classify.')
|