Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tensorflow.keras.preprocessing.text import Tokenizer
|
2 |
+
from tensorflow.keras.preprocessing import sequence
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
import numpy as np
|
5 |
+
import gradio as gr
|
6 |
+
model = load_model('trained.h5')
|
7 |
+
|
8 |
+
tokenizer = Tokenizer()
|
9 |
+
def encoder(text):
|
10 |
+
text = tokenizer.texts_to_sequences([text])
|
11 |
+
text = sequence.pad_sequences(text, maxlen=200)
|
12 |
+
return text
|
13 |
+
|
14 |
+
def predict(text):
|
15 |
+
encoded_text = encoder(text)
|
16 |
+
#print(encoded_text)
|
17 |
+
prediction = (model.predict(encoded_text))
|
18 |
+
print(prediction)
|
19 |
+
prediction = np.round(prediction)
|
20 |
+
if prediction==1:
|
21 |
+
return "Disaster"
|
22 |
+
return "Not a Disaster"
|
23 |
+
|
24 |
+
title="Relevance Classifier"
|
25 |
+
description="<p style='text-align:center'>Classifies input text into Disaster-related or not disaster related."
|
26 |
+
|
27 |
+
gr.Interface(fn=predict, inputs='text', output='text', title=title, description=description).launch()
|