Last active
January 22, 2023 13:38
-
-
Save merlin-quix/9fac05af47b00af5dd14483942b14566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for message in consumer: | |
# Get the message body | |
m=message.value | |
# Turn the message back into a DataFrame | |
df=DataFrame(m,index=[0]) | |
# Extract the Message from the DataFrame | |
dff = pd.Series(df['MessageBody']) | |
# Get a spam prediction for the message | |
prediction = (model.predict(dff) > 0.5).astype(int) | |
# Create a new message with the MessageID and the SpamFlag | |
data = {'SpamFlag': prediction[0][0], | |
'MessageID': m['MessageID']} | |
# Print the message so you can see what is being sent | |
print(f'Sending message: {data}') | |
# Send the message containing the prediction to the predictions topic | |
producer.send(topic="predictions",value=data) | |
print(f'Sent record to topic at time {dt.datetime.utcnow()}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment