s1ri1337's picture
Create new file
3633936
raw
history blame
894 Bytes
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing import sequence
from tensorflow.keras.models import load_model
import numpy as np
import gradio as gr
model = load_model('trained.h5')
tokenizer = Tokenizer()
def encoder(text):
text = tokenizer.texts_to_sequences([text])
text = sequence.pad_sequences(text, maxlen=200)
return text
def predict(text):
encoded_text = encoder(text)
#print(encoded_text)
prediction = (model.predict(encoded_text))
print(prediction)
prediction = np.round(prediction)
if prediction==1:
return "Disaster"
return "Not a Disaster"
title="Relevance Classifier"
description="<p style='text-align:center'>Classifies input text into Disaster-related or not disaster related."
gr.Interface(fn=predict, inputs='text', output='text', title=title, description=description).launch()