Commit
·
2c64837
1
Parent(s):
e3a39c5
commit
Browse files
app.py
CHANGED
|
@@ -21,9 +21,6 @@ def generate_caption_and_analyze_emotions(image):
|
|
| 21 |
# Decode the output caption
|
| 22 |
decoded_caption = caption_processor.decode(caption[0], skip_special_tokens=True)
|
| 23 |
|
| 24 |
-
# Debug print for the raw output caption
|
| 25 |
-
print("Raw Generated Caption:", decoded_caption)
|
| 26 |
-
|
| 27 |
# Analyze emotions of the generated caption
|
| 28 |
# Preprocess the caption for emotion analysis
|
| 29 |
emotion_inputs = emotion_tokenizer.encode_plus(
|
|
@@ -36,11 +33,9 @@ def generate_caption_and_analyze_emotions(image):
|
|
| 36 |
emotion_outputs = emotion_model(**emotion_inputs)
|
| 37 |
|
| 38 |
# Get the predicted emotion label
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
-
# Debug print for caption and emotion label
|
| 42 |
-
#print("Generated Caption:", decoded_caption)
|
| 43 |
-
#print("Predicted Emotion Label:", emotion_label)
|
| 44 |
|
| 45 |
# Prepare the final output with sentiment information
|
| 46 |
final_output = f"The sentiment in the provided image shows: {emotion_label}.\n\nGenerated Caption: {decoded_caption}"
|
|
|
|
| 21 |
# Decode the output caption
|
| 22 |
decoded_caption = caption_processor.decode(caption[0], skip_special_tokens=True)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
# Analyze emotions of the generated caption
|
| 25 |
# Preprocess the caption for emotion analysis
|
| 26 |
emotion_inputs = emotion_tokenizer.encode_plus(
|
|
|
|
| 33 |
emotion_outputs = emotion_model(**emotion_inputs)
|
| 34 |
|
| 35 |
# Get the predicted emotion label
|
| 36 |
+
emotion_label_id = emotion_outputs.logits.argmax().item()
|
| 37 |
+
emotion_label = emotion_tokenizer.decode(emotion_label_id)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Prepare the final output with sentiment information
|
| 41 |
final_output = f"The sentiment in the provided image shows: {emotion_label}.\n\nGenerated Caption: {decoded_caption}"
|