Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow import keras
|
3 |
+
import numpy as np
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
tokenizer = tf.keras.preprocessing.text.Tokenizer()
|
7 |
+
|
8 |
+
#Reads Text Inputs Here
|
9 |
+
f=open('Inputs.txt','r')
|
10 |
+
inputs = f.read().split('\n')
|
11 |
+
f.close()
|
12 |
+
|
13 |
+
corpus = inputs
|
14 |
+
|
15 |
+
tokenizer.fit_on_texts(corpus)
|
16 |
+
sequences = tokenizer.texts_to_sequences(corpus)
|
17 |
+
|
18 |
+
max_length = max([len(s) for s in sequences])
|
19 |
+
|
20 |
+
# Load your saved model
|
21 |
+
model = tf.keras.models.load_model('sentiment_mini-test')
|
22 |
+
|
23 |
+
def use(input_text):
|
24 |
+
# Preprocess the input text
|
25 |
+
sequences = tokenizer.texts_to_sequences([input_text])
|
26 |
+
sequences = tf.keras.preprocessing.sequence.pad_sequences(sequences, padding='post', maxlen=max_length)
|
27 |
+
|
28 |
+
# Make a prediction on the input text
|
29 |
+
prediction = model.predict(sequences)[0]
|
30 |
+
|
31 |
+
# Print the prediction
|
32 |
+
return round(prediction[0])
|
33 |
+
|
34 |
+
|
35 |
+
iface = gr.Interface(fn=use, inputs="text", outputs="text")
|
36 |
+
iface.launch()
|