GirishKiran commited on
Commit
08172bd
1 Parent(s): fa5774d

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -221,11 +221,12 @@ def _predict_sentiment(p):
221
  scores = scipy.special.softmax(scores)
222
  sentiment_map = ['Sadness', 'Joy', 'Love', 'Anger', 'Fear' , "Surprise"]
223
  df_out = pandas.DataFrame([scores], columns=sentiment_map)
 
224
  return df_out
225
 
226
  @add_method(SentimentAnalyser)
227
  def draw_bar_plot(df_data, title='Sentiment Analysis', xlabel='p string', ylabel='Emotion Score'):
228
- pic = df_data.plot.bar(color=['#e89096', '#747c0c', '#84c98c','#dc545c', '#a31a0e' , '#3fbfbf'],
229
  title=title,
230
  ylabel=ylabel,
231
  xlabel=xlabel,
@@ -235,6 +236,7 @@ def draw_bar_plot(df_data, title='Sentiment Analysis', xlabel='p string', ylabel
235
  @add_method(SentimentAnalyser)
236
  def predict_sentiment(p):
237
  df_out = _predict_sentiment(p)
 
238
  max_column = df_out.loc[0].idxmax()
239
  max_value = df_out.loc[0].max()
240
  title = f'Sentiment Analysis: {max_column}: {round(max_value*100,1)}%'
@@ -242,16 +244,20 @@ def predict_sentiment(p):
242
  pic = draw_bar_plot(df_out, title=title, xlabel=xlabel)
243
  return pic.get_figure(), df_out.to_json()
244
 
245
-
246
  import gradio
247
  in_box = [gradio.Textbox(lines=1, label="Input", placeholder="type text here")]
248
  out_box = [gradio.Plot(label="Sentiment Score:"),
249
  gradio.Textbox(lines=4, label="Raw JSON Response:")]
250
  title = "Sentiment Analysis: Understanding the Emotional Tone of Text"
251
- desc = "Sentiment analysis is a powerful tool that can be used to gain insights into how people feel about the world around them."
 
 
 
 
252
 
253
  gradio.Interface(fn=predict_sentiment,
254
  inputs=in_box,
255
  outputs=out_box,
256
  title=title,
257
- description=desc).launch(debug=True)
 
 
221
  scores = scipy.special.softmax(scores)
222
  sentiment_map = ['Sadness', 'Joy', 'Love', 'Anger', 'Fear' , "Surprise"]
223
  df_out = pandas.DataFrame([scores], columns=sentiment_map)
224
+ df_out = df_out[['Love' , 'Joy', 'Surprise' , 'Fear', 'Sadness', 'Anger']]
225
  return df_out
226
 
227
  @add_method(SentimentAnalyser)
228
  def draw_bar_plot(df_data, title='Sentiment Analysis', xlabel='p string', ylabel='Emotion Score'):
229
+ pic = df_data.plot.bar(color=['#84c98c', '#747c0c', '#3fbfbf','#e89096', '#dc545c' , '#a31a0e'],
230
  title=title,
231
  ylabel=ylabel,
232
  xlabel=xlabel,
 
236
  @add_method(SentimentAnalyser)
237
  def predict_sentiment(p):
238
  df_out = _predict_sentiment(p)
239
+ print("sort : ", df_out.sort_values(['Love', 'Joy', 'Surprise', 'Fear', 'Sadness', 'Anger']))
240
  max_column = df_out.loc[0].idxmax()
241
  max_value = df_out.loc[0].max()
242
  title = f'Sentiment Analysis: {max_column}: {round(max_value*100,1)}%'
 
244
  pic = draw_bar_plot(df_out, title=title, xlabel=xlabel)
245
  return pic.get_figure(), df_out.to_json()
246
 
 
247
  import gradio
248
  in_box = [gradio.Textbox(lines=1, label="Input", placeholder="type text here")]
249
  out_box = [gradio.Plot(label="Sentiment Score:"),
250
  gradio.Textbox(lines=4, label="Raw JSON Response:")]
251
  title = "Sentiment Analysis: Understanding the Emotional Tone of Text"
252
+ desc = "Sentiment analysis is a powerful tool that can be used to gain insights into how people feel about the world around them."
253
+ exp = [
254
+ ['I am feeling very bad today.'],
255
+ ['I hate to swim early morning.']
256
+ ]
257
 
258
  gradio.Interface(fn=predict_sentiment,
259
  inputs=in_box,
260
  outputs=out_box,
261
  title=title,
262
+ description=desc,
263
+ examples=exp).launch(debug=True)