Kawthar12h
commited on
Commit
•
7cd21ae
1
Parent(s):
40fe0fb
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
|
|
4 |
import torch
|
5 |
import requests
|
6 |
import re
|
7 |
-
from transformers import pipeline,
|
8 |
|
9 |
# load image examples
|
10 |
img_urls_1 = ['https://i.pinimg.com/564x/f7/f5/bd/f7f5bd929e05a852ff423e6e02deea54.jpg', 'https://i.pinimg.com/564x/b4/29/69/b4296962cb76a72354a718109835caa3.jpg',
|
@@ -21,8 +21,8 @@ for idx2, url2 in enumerate(img_urls_2):
|
|
21 |
image.save(f"tx_image_{idx2}.png")
|
22 |
|
23 |
# Load Blip model and processor for captioning
|
24 |
-
processor_blip = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-
|
25 |
-
model_blip = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-
|
26 |
|
27 |
# Load marefa model for translation (English to Arabic)
|
28 |
translate = pipeline("translation",model="marefa-nlp/marefa-mt-en-ar")
|
@@ -32,7 +32,7 @@ def caption_and_translate(img, min_len, max_len):
|
|
32 |
raw_image = Image.open(img).convert('RGB')
|
33 |
inputs_blip = processor_blip(raw_image, return_tensors="pt")
|
34 |
|
35 |
-
out_blip = model_blip.generate(**inputs_blip, min_length=
|
36 |
english_caption = processor_blip.decode(out_blip[0], skip_special_tokens=True)
|
37 |
|
38 |
# Translate caption from English to Arabic
|
|
|
4 |
import torch
|
5 |
import requests
|
6 |
import re
|
7 |
+
from transformers import pipeline,BlipProcessor, BlipForConditionalGeneration, TrOCRProcessor, VisionEncoderDecoderModel
|
8 |
|
9 |
# load image examples
|
10 |
img_urls_1 = ['https://i.pinimg.com/564x/f7/f5/bd/f7f5bd929e05a852ff423e6e02deea54.jpg', 'https://i.pinimg.com/564x/b4/29/69/b4296962cb76a72354a718109835caa3.jpg',
|
|
|
21 |
image.save(f"tx_image_{idx2}.png")
|
22 |
|
23 |
# Load Blip model and processor for captioning
|
24 |
+
processor_blip = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
25 |
+
model_blip = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
26 |
|
27 |
# Load marefa model for translation (English to Arabic)
|
28 |
translate = pipeline("translation",model="marefa-nlp/marefa-mt-en-ar")
|
|
|
32 |
raw_image = Image.open(img).convert('RGB')
|
33 |
inputs_blip = processor_blip(raw_image, return_tensors="pt")
|
34 |
|
35 |
+
out_blip = model_blip.generate(**inputs_blip, min_length=min_len, max_length=max_len)
|
36 |
english_caption = processor_blip.decode(out_blip[0], skip_special_tokens=True)
|
37 |
|
38 |
# Translate caption from English to Arabic
|