DemahAlmutairi commited on
Commit
1c55ce7
·
verified ·
1 Parent(s): 20effa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
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
- # Function to process the image
17
- def process_image(image):
18
- caption = caption_image(image)[0]['generated_text']
19
- return caption
20
 
21
- # Create Gradio interface with example images
22
- iface = gr.Interface(
23
- fn=process_image,
 
 
 
 
 
24
  inputs=gr.Image(type="pil"),
25
- outputs=gr.Textbox(label="Generated Caption"),
26
- examples=example_images # Use local images as examples
 
 
 
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()