AmandaPanda commited on
Commit
ef8e1c9
·
verified ·
1 Parent(s): ff9f4e9

Load pandas df, load dataset, print first 12 images. get image database (merve/coco). Randomly select image (include dir, root, file)

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py CHANGED
@@ -3,5 +3,57 @@ import gradio as gr
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
7
  demo.launch()
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
+
7
+
8
+ # Load vision capability to support image display
9
+ pip install datasets[vision]
10
+
11
+ # Load pandas for grid display
12
+ pip install pandas
13
+ import pandas as pd
14
+
15
+
16
+ # Load database (merve/coco)
17
+ from datasets import load_dataset
18
+ dataset = load_dataset("merve/coco")
19
+
20
+ df = pd.dataset
21
+ print(df.head(12))
22
+
23
+
24
+ # Get image database
25
+ ##curl -X GET \
26
+ ## "https://datasets-server.huggingface.co/first-rows?dataset=merve%2Fcoco&config=default&split=validation"
27
+
28
+ # Load transformer Salesforce/blip image captioning
29
+ # Load model directly
30
+ ##from transformers import AutoProcessor, AutoModelForVision2Seq
31
+
32
+ ##processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
33
+ ##model = AutoModelForVision2Seq.from_pretrained("Salesforce/blip-image-captioning-large")
34
+
35
+
36
+ import os
37
+ import random
38
+
39
+ path = "https://huggingface.co/Salesforce/blip-image-captioning-large"
40
+
41
+ images = []
42
+
43
+ # This will get each root, dir and file list in the path specified recursively (like the "find" command in linux, but separating files, from directories, from paths).
44
+ # root is the full path from your specified path to the the directory it is inspecting
45
+ # dirs is a list containing all the directories found in the current inspecting directory
46
+ # files is a list containing all the files found in the current inspecting directory
47
+ for root, dirs, files in os.walk(path):
48
+ # This will filter all the .png files in case there is something else in the directory
49
+ # If your directory only has images, you can do this:
50
+ # images = files
51
+ # instead of filtering the '.png' images with the for loop // filter for jgp
52
+ for f in files:
53
+ if f[-4:] == '.jpg':
54
+ images.append(f)
55
+
56
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
57
+
58
+ print(random.choice(images))
59
  demo.launch()