Walid-Ahmed commited on
Commit
7d6946d
·
verified ·
1 Parent(s): a0c84cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -16,6 +16,36 @@ caption_image = pipeline("image-to-text", model="Salesforce/blip-image-captionin
16
  narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs", device=device)
17
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def process_image(image):
20
  # Generate the caption
21
  caption = caption_image(image)[0]['generated_text']
@@ -37,6 +67,7 @@ iface = gr.Interface(
37
  fn=process_image,
38
  inputs=gr.Image(type="pil"),
39
  outputs=[gr.Textbox(label="Generated Caption"), gr.Audio(label="Generated Audio", type="filepath")]
 
40
  )
41
 
42
  # Launch the interface
 
16
  narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs", device=device)
17
 
18
 
19
+ # URLs of the images
20
+ image_urls = [
21
+ "https://github.com/Walid-Ahmed/ML_Datasets/blob/master/image1.jpeg?raw=true",
22
+ "https://github.com/Walid-Ahmed/ML_Datasets/blob/master/image2.jpeg?raw=true",
23
+ "https://github.com/Walid-Ahmed/ML_Datasets/blob/master/image3.jpeg?raw=true"
24
+ ]
25
+
26
+ # Directory to save images
27
+ save_dir = "example_images"
28
+ os.makedirs(save_dir, exist_ok=True)
29
+
30
+ # Function to download images
31
+ def download_image(url, filename):
32
+ response = requests.get(url)
33
+ if response.status_code == 200:
34
+ with open(filename, "wb") as f:
35
+ f.write(response.content)
36
+ return filename
37
+ else:
38
+ print(f"Failed to download: {url}")
39
+ return None
40
+
41
+ # Download images
42
+ example_images = []
43
+ for idx, url in enumerate(image_urls):
44
+ img_path = os.path.join(save_dir, f"image{idx+1}.jpeg")
45
+ if not os.path.exists(img_path): # Avoid redownloading if already exists
46
+ download_image(url, img_path)
47
+ example_images.append(img_path)
48
+
49
  def process_image(image):
50
  # Generate the caption
51
  caption = caption_image(image)[0]['generated_text']
 
67
  fn=process_image,
68
  inputs=gr.Image(type="pil"),
69
  outputs=[gr.Textbox(label="Generated Caption"), gr.Audio(label="Generated Audio", type="filepath")]
70
+ examples=example_images
71
  )
72
 
73
  # Launch the interface