AmandaPanda commited on
Commit
b68a7f1
·
verified ·
1 Parent(s): a85e974

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,5 +1,7 @@
1
  # Import gradio - app framework
2
  import gradio as gr
 
 
3
 
4
  # Import pandas datasets, transformers, torch
5
  import pandas as pd
@@ -32,6 +34,15 @@ samples = dataset.select(range(20))
32
  #Convert to dataframe
33
  df = pd.DataFrame(samples)
34
 
 
 
 
 
 
 
 
 
 
35
  ## print ("Print to show the 20 images available.")
36
  ## print ("The app will then select an image for further exploration.")
37
  ## print(df.head(20))
@@ -50,11 +61,18 @@ trans_model = MarianMTModel.from_pretrained(model_name)
50
  #Configure captioning function
51
  def caption_random_image():
52
 
53
- # pick random row
54
- sample = df.sample(1).iloc[0]
 
 
 
 
 
 
 
55
 
56
- # 'image' field contains an actual PIL image
57
- image = sample["image"]
58
 
59
  # Unconditional image captioning
60
  inputs = processor(image, return_tensors="pt")
 
1
  # Import gradio - app framework
2
  import gradio as gr
3
+ import os
4
+ import random
5
 
6
  # Import pandas datasets, transformers, torch
7
  import pandas as pd
 
34
  #Convert to dataframe
35
  df = pd.DataFrame(samples)
36
 
37
+ # Direct to Photos folder
38
+ IMAGE_FOLDER = "Photos"
39
+
40
+ image_paths = [
41
+ os.path.join(IMAGE_FOLDER, f)
42
+ for f in os.listdir(IMAGE_FOLDER)
43
+ if f.lower().endswith((".jpg", ".jpeg", ".png"))
44
+ ]
45
+
46
  ## print ("Print to show the 20 images available.")
47
  ## print ("The app will then select an image for further exploration.")
48
  ## print(df.head(20))
 
61
  #Configure captioning function
62
  def caption_random_image():
63
 
64
+ # pick random row - from DF
65
+ ##sample = df.sample(1).iloc[0]
66
+
67
+ # Pick a random image path
68
+ img_path = random.choice(image_paths)
69
+
70
+ # Load into PIL
71
+ image = Image.open(img_path).convert("RGB")
72
+
73
 
74
+ # 'image' field contains an actual PIL image - for DF
75
+ ##image = sample["image"]
76
 
77
  # Unconditional image captioning
78
  inputs = processor(image, return_tensors="pt")