Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,22 +9,31 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
9 |
|
10 |
# Load the image-to-text pipeline
|
11 |
caption_image = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large", device=device)
|
|
|
12 |
|
13 |
# List of local image paths
|
14 |
example_images = ["flower.jpg"]
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
caption =
|
19 |
-
return caption
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
inputs=gr.Image(type="pil"),
|
25 |
-
outputs=gr.
|
26 |
-
|
|
|
|
|
|
|
27 |
)
|
28 |
|
|
|
29 |
# Launch the interface
|
30 |
iface.launch()
|
|
|
9 |
|
10 |
# Load the image-to-text pipeline
|
11 |
caption_image = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large", device=device)
|
12 |
+
translate = pipeline("translation_en_to_ar", model="Helsinki-NLP/opus-mt-en-ar")
|
13 |
|
14 |
# List of local image paths
|
15 |
example_images = ["flower.jpg"]
|
16 |
|
17 |
+
def Arabic_Image_Captioning(image):
|
18 |
+
caption = caption_image(image)
|
19 |
+
caption = caption[0]['generated_text']
|
|
|
20 |
|
21 |
+
arabic_caption = translate(caption)
|
22 |
+
arabic_caption = arabic_caption[0]['translation_text']
|
23 |
+
|
24 |
+
html_result = f'<div dir="rtl">{arabic_caption}</div>'
|
25 |
+
return html_result
|
26 |
+
|
27 |
+
demo = gr.Interface(
|
28 |
+
fn=Arabic_Image_Captioning,
|
29 |
inputs=gr.Image(type="pil"),
|
30 |
+
outputs=gr.HTML(label="Caption in Arabic"),
|
31 |
+
title="Arabic Image Captioning",
|
32 |
+
description="Upload an image to generate an arabic caption.",
|
33 |
+
examples=example_images
|
34 |
+
|
35 |
)
|
36 |
|
37 |
+
|
38 |
# Launch the interface
|
39 |
iface.launch()
|