Sambhavnoobcoder commited on
Commit
6ed2700
·
1 Parent(s): 9a811e6
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -22,20 +22,28 @@ def predict_sentiment(text):
22
  # Normalize the probabilities
23
  proba /= proba.sum()
24
  # Return the probability distribution
25
- return {"Positive": float(proba[0]), "Negative": float(proba[1]), "Neutral": float(proba[2])}
26
 
27
- # Create a Gradio interface
 
 
 
28
  iface = gr.Interface(
29
- fn=predict_sentiment,
30
- inputs=gr.inputs.Textbox(label="Enter text here"),
31
- outputs=gr.outputs.Plotly(title="Sentiment Distribution", x="Sentiment", y="Probability")
 
 
 
 
 
32
  )
33
 
34
- # Define the possible classes
35
- classes = ["Positive", "Negative", "Neutral"]
36
-
37
- # Add the possible classes to the output plot
38
- iface.outputs[0].type.bar.labels = classes
39
 
40
  # Launch the interface
41
  iface.launch()
 
22
  # Normalize the probabilities
23
  proba /= proba.sum()
24
  # Return the probability distribution
25
+ return {'Positive': float(proba[0]), 'Negative': float(proba[1]), 'Neutral': float(proba[2])}
26
 
27
+ # Define the possible classes
28
+ classes = ['Positive', 'Negative', 'Neutral']
29
+
30
+ # Define the Gradio interface
31
  iface = gr.Interface(
32
+ fn=predict_sentiment,
33
+ inputs=gr.inputs.Textbox(label='Enter text here'),
34
+ outputs=gr.outputs.Bar(label='Sentiment Distribution',
35
+ colors=['#2a9d8f', '#e76f51', '#264653'],
36
+ value=[0.3, 0.3, 0.3],
37
+ min=0,
38
+ max=1),
39
+ title='SENTIMENT ANALYSIS'
40
  )
41
 
42
+ # Set the class labels for the output
43
+ iface.outputs[0].type = 'bar'
44
+ iface.outputs[0].label = 'Sentiment Distribution'
45
+ iface.outputs[0].determine_labels_from_data = False
46
+ iface.outputs[0].labels = classes
47
 
48
  # Launch the interface
49
  iface.launch()