AjayKr09 commited on
Commit
41f5877
·
verified ·
1 Parent(s): 7b35252

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -9,26 +9,22 @@ load_dotenv()
9
  # Get your OpenAI API key from the environment variables
10
  openai.api_key = os.getenv('OPENAI_API_KEY')
11
 
12
- # Function to classify email
13
- def classify_email(email_text):
14
- response = openai.ChatCompletion.create(
 
 
 
15
  model='gpt-3.5-turbo',
16
  messages=[
17
  {"role": "system", "content": "You are an email classifier."},
18
  {"role": "user", "content": f"Classify the following email:\n\n{email_text}\n\nCategories: Spam, Work, Personal, Promotion, Other"}
19
  ]
20
  )
21
- return response['choices'][0]['message']['content'].strip()
22
 
23
- # Streamlit interface
24
- st.title('Email Classifier')
25
- st.write('Enter the email text below and click "Classify" to determine its category.')
26
-
27
- email_text = st.text_area('Email Text', height=300)
28
 
29
  if st.button('Classify'):
30
  if email_text:
31
- category = classify_email(email_text)
32
- st.write(f'The email is classified as: **{category}**')
33
  else:
34
  st.write('Please enter some text to classify.')
 
9
  # Get your OpenAI API key from the environment variables
10
  openai.api_key = os.getenv('OPENAI_API_KEY')
11
 
12
+ # Streamlit interface
13
+ st.title('Email Classifier')
14
+
15
+ email_text = st.text_area('Email Text', height=300)
16
+
17
+ response = 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
 
26
  if 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.')