Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,10 @@ caption_pipeline = pipeline("image-to-text", model="Salesforce/blip-image-captio
|
|
8 |
# Initialize the pipeline for emotion classification
|
9 |
emotion_pipeline = pipeline("image-classification", model="RickyIG/emotion_face_image_classification_v3")
|
10 |
|
11 |
-
|
|
|
|
|
|
|
12 |
# Process the image for captioning
|
13 |
caption_result = caption_pipeline(image)
|
14 |
caption = caption_result[0]["generated_text"]
|
@@ -17,13 +20,16 @@ def generate_caption_and_emotion(image):
|
|
17 |
emotion_result = emotion_pipeline(image)
|
18 |
emotions = ", ".join([f"{res['label']}: {res['score']:.2f}" for res in emotion_result])
|
19 |
|
|
|
|
|
|
|
|
|
20 |
# Combine results
|
21 |
-
combined_result = f"Caption: {caption}\nEmotions: {emotions}"
|
22 |
return combined_result
|
23 |
|
24 |
# Setup the Gradio interface
|
25 |
-
interface = gr.Interface(fn=
|
26 |
inputs=gr.components.Image(type="pil", label="Upload an Image"),
|
27 |
-
outputs=gr.components.Textbox(label="Generated Caption and
|
28 |
interface.launch()
|
29 |
-
|
|
|
8 |
# Initialize the pipeline for emotion classification
|
9 |
emotion_pipeline = pipeline("image-classification", model="RickyIG/emotion_face_image_classification_v3")
|
10 |
|
11 |
+
# Initialize the pipeline for object detection
|
12 |
+
object_pipeline = pipeline("object-detection", model="facebook/detr-resnet-50")
|
13 |
+
|
14 |
+
def generate_caption_emotion_and_objects(image):
|
15 |
# Process the image for captioning
|
16 |
caption_result = caption_pipeline(image)
|
17 |
caption = caption_result[0]["generated_text"]
|
|
|
20 |
emotion_result = emotion_pipeline(image)
|
21 |
emotions = ", ".join([f"{res['label']}: {res['score']:.2f}" for res in emotion_result])
|
22 |
|
23 |
+
# Process the image for object detection
|
24 |
+
object_result = object_pipeline(image)
|
25 |
+
objects = ", ".join([f"{obj['label']}: {obj['score']:.2f}" for obj in object_result])
|
26 |
+
|
27 |
# Combine results
|
28 |
+
combined_result = f"Caption: {caption}\nEmotions: {emotions}\nObjects: {objects}"
|
29 |
return combined_result
|
30 |
|
31 |
# Setup the Gradio interface
|
32 |
+
interface = gr.Interface(fn=generate_caption_emotion_and_objects,
|
33 |
inputs=gr.components.Image(type="pil", label="Upload an Image"),
|
34 |
+
outputs=gr.components.Textbox(label="Generated Caption, Emotions, and Objects Detected"))
|
35 |
interface.launch()
|
|