muneebashraf commited on
Commit
0541682
·
1 Parent(s): d2fe332
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -22,16 +22,19 @@ def generate_caption_and_analyze_emotions(image):
22
  emotion_classifier = pipeline(model=emotion_model_name)
23
 
24
  results = emotion_classifier(decoded_caption)
25
- if results[0]['label'] == 'neutral' or results[0]['score'] <= 0.40:
26
- final_output = f"Sentiment of image is not clear, image shows {decoded_caption}."
 
27
  else:
28
- final_output = f"Sentiment of the image shows {results[0]['label']}."
 
 
29
 
30
  return final_output
31
 
32
  # Define the Gradio interface
33
  inputs = gr.inputs.Image(label="Upload an image")
34
- outputs = gr.outputs.Textbox(label="Sentiment Analysis")
35
 
36
  # Create the Gradio app
37
  app = gr.Interface(fn=generate_caption_and_analyze_emotions, inputs=inputs, outputs=outputs)
 
22
  emotion_classifier = pipeline(model=emotion_model_name)
23
 
24
  results = emotion_classifier(decoded_caption)
25
+ sentiment_label = results[0]['label']
26
+ if sentiment_label == 'neutral':
27
+ sentiment_text = "Sentiment of the image is"
28
  else:
29
+ sentiment_text = "Sentiment of the image shows"
30
+
31
+ final_output = f"This image shows {decoded_caption} and {sentiment_text} {sentiment_label}."
32
 
33
  return final_output
34
 
35
  # Define the Gradio interface
36
  inputs = gr.inputs.Image(label="Upload an image")
37
+ outputs = gr.outputs.Textbox(label="Generated Caption and Sentiment Analysis")
38
 
39
  # Create the Gradio app
40
  app = gr.Interface(fn=generate_caption_and_analyze_emotions, inputs=inputs, outputs=outputs)