MrSalman commited on
Commit
235ef43
1 Parent(s): bba69da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -14,13 +14,10 @@ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-capt
14
  model_translater = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-ar")
15
 
16
  # conditional image captioning (with prefix-)
17
- def image_captioning(image_url, prefix="a "):
18
  """ Return text (As str) to describe an image """
19
- # Get the image by image_url and convert it to RGB
20
- raw_image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
21
-
22
  # Process the image
23
- inputs = processor(raw_image, prefix, return_tensors="pt")
24
 
25
  # Generate text to describe the image
26
  output = model.generate(**inputs)
@@ -34,9 +31,9 @@ def translate_text(text, to="ar"):
34
  translated_text = model_translater(str(text))
35
  return translated_text[0]['translation_text']
36
 
37
- def image_captioning_ar(image_url, prefix = "a "):
38
- if image_url:
39
- text = image_captioning(image_url, prefix=prefix)
40
  return translate_text(text)
41
  return null
42
 
 
14
  model_translater = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-ar")
15
 
16
  # conditional image captioning (with prefix-)
17
+ def image_captioning(image, prefix="a "):
18
  """ Return text (As str) to describe an image """
 
 
 
19
  # Process the image
20
+ inputs = processor(image, prefix, return_tensors="pt")
21
 
22
  # Generate text to describe the image
23
  output = model.generate(**inputs)
 
31
  translated_text = model_translater(str(text))
32
  return translated_text[0]['translation_text']
33
 
34
+ def image_captioning_ar(image, prefix = "a "):
35
+ if image:
36
+ text = image_captioning(image, prefix=prefix)
37
  return translate_text(text)
38
  return null
39