Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,20 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
from transformers import BertTokenizer, TFBertForSequenceClassification
|
| 3 |
import tensorflow as tf
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Load the model and tokenizer
|
| 6 |
model_name = "EScO-V10/Mail_Classification_Model"
|
| 7 |
model = TFBertForSequenceClassification.from_pretrained(model_name)
|
| 8 |
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def classify_email(email_body):
|
| 11 |
# Tokenize the input string
|
| 12 |
inputs = tokenizer.encode_plus(
|
|
@@ -36,10 +44,10 @@ def classify_email(email_body):
|
|
| 36 |
sentiment = 'Event' if predicted_class == 1 else 'Non-Event'
|
| 37 |
return sentiment
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
classification_result = classify_email(email_body)
|
| 45 |
-
st.write(f"Sentiment: {classification_result}")
|
|
|
|
|
|
|
| 1 |
from transformers import BertTokenizer, TFBertForSequenceClassification
|
| 2 |
import tensorflow as tf
|
| 3 |
+
from fastapi import FastAPI, Request
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
import uvicorn
|
| 6 |
|
| 7 |
# Load the model and tokenizer
|
| 8 |
model_name = "EScO-V10/Mail_Classification_Model"
|
| 9 |
model = TFBertForSequenceClassification.from_pretrained(model_name)
|
| 10 |
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 11 |
|
| 12 |
+
# Define the FastAPI app
|
| 13 |
+
app = FastAPI()
|
| 14 |
+
|
| 15 |
+
class EmailBody(BaseModel):
|
| 16 |
+
email_body: str
|
| 17 |
+
|
| 18 |
def classify_email(email_body):
|
| 19 |
# Tokenize the input string
|
| 20 |
inputs = tokenizer.encode_plus(
|
|
|
|
| 44 |
sentiment = 'Event' if predicted_class == 1 else 'Non-Event'
|
| 45 |
return sentiment
|
| 46 |
|
| 47 |
+
@app.post("/classify")
|
| 48 |
+
async def classify(email_body: EmailBody):
|
| 49 |
+
sentiment = classify_email(email_body.email_body)
|
| 50 |
+
return {"sentiment": sentiment}
|
| 51 |
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
|
|