Sambhavnoobcoder commited on
Commit
21a1937
·
1 Parent(s): f3335c0

direct uthaya

Browse files
Files changed (1) hide show
  1. app.py +1 -31
app.py CHANGED
@@ -1,33 +1,3 @@
1
  import gradio as gr
2
- import tensorflow as tf
3
 
4
- # Load the pre-trained model
5
- model = tf.keras.models.load_model('sentimentality.h5')
6
-
7
- # Define a function to make a prediction on the input text
8
- def predict_sentiment(text):
9
- # Preprocess the text
10
- tokenizer = tf.keras.preprocessing.text.Tokenizer()
11
- tokenizer.fit_on_texts([text])
12
- text = tokenizer.texts_to_sequences([text])
13
- text = tf.keras.preprocessing.sequence.pad_sequences(text, maxlen=500, padding='post', truncating='post')
14
- # Make a prediction using the loaded model
15
- proba = model.predict(text)[0]
16
- # Normalize the probabilities
17
- proba /= proba.sum()
18
- # Return the probability distribution
19
- return {"Positive": float(proba[0]), "Negative": float(proba[1]), "Neutral": float(proba[2])}
20
-
21
- # Create a Gradio interface
22
- iface = gr.Interface(
23
- fn=predict_sentiment,
24
- inputs=gr.inputs.Textbox(label="Enter text here", lines=5, placeholder="Type here to analyze sentiment..."),
25
- outputs=gr.outputs.Label(label="Sentiment", default="Neutral", font_size=30)
26
- )
27
-
28
- # Add the possible classes to the output plot
29
- classes = ["Positive", "Negative", "Neutral"]
30
- iface.outputs[0].choices = classes
31
-
32
- # Launch the interface
33
- iface.launch()
 
1
  import gradio as gr
 
2
 
3
+ gr.Interface.load("sentimentality.h5").launch()