davanstrien HF staff commited on
Commit
235f6a0
1 Parent(s): f736a5a

update text

Browse files
Files changed (1) hide show
  1. app.py +32 -21
app.py CHANGED
@@ -11,6 +11,7 @@ import os
11
  import backoff
12
  from functools import lru_cache
13
  from huggingface_hub import list_models, ModelFilter, login
 
14
 
15
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
16
 
@@ -127,18 +128,18 @@ def predict_subset(model_id, token):
127
 
128
 
129
  with gr.Blocks() as demo:
130
- with gr.Tab("Random image gallery"):
131
  gr.Markdown(
132
- """## Random image gallery
133
- This is a random image gallery.
134
- You can refresh the images by clicking the refresh button."""
135
  )
136
  button = gr.Button("Refresh")
137
  gallery = gr.Gallery().style(grid=9, height="1400")
138
  button.click(return_random_sample, [], [gallery])
139
- with gr.Tab("image search"):
140
  gr.Markdown(
141
- """## Image search
142
  You can search for images by entering a search term and clicking the search button.
143
  You can also change the number of images to be returned.
144
  This model uses the [clip-ViT-B-16](https://huggingface.co/sentence-transformers/clip-ViT-B-16) model to embed your images and search term"""
@@ -148,27 +149,37 @@ with gr.Blocks() as demo:
148
  button = gr.Button("search")
149
  gallery = gr.Gallery().style(grid=3)
150
  button.click(get_nearest_k_examples, [text, k], [gallery])
151
- gr.Markdown("""### More info
152
- ![https://raw.githubusercontent.com/UKPLab/sentence-transformers/master/docs/img/ImageSearch.png](https://raw.githubusercontent.com/UKPLab/sentence-transformers/master/docs/img/ImageSearch.png)""")
153
- # with gr.Tab("Export for label studio"):
154
- # button = gr.Button("Export")
155
- # dataset2 = copy.deepcopy(dataset)
156
- # # dataset2 = dataset2.remove_columns('image')
157
- # # dataset2 = dataset2.rename_column("url", "image")
158
- # csv = dataset2.to_csv("label_studio.csv")
159
- # csv_file = gr.File("label_studio.csv")
160
- # button.click(dataset.save_to_disk, [], [csv_file])
161
- with gr.Tab("predict"):
162
  gr.Markdown(
163
- """## Image classification model tester
164
- You can use this to test out [image classification models](https://huggingface.co/models?pipeline_tag=image-classification) on the Hugging Face Hub. """
 
 
 
 
 
 
165
  )
166
  token = gr.Textbox(label="token", type="password")
167
- model_id = gr.Textbox(label="model_id")
168
  button = gr.Button("predict")
169
  gr.Markdown("## Results")
170
  plot = gr.BarPlot(x="labels", y="freqs", width=600, height=400, vertical=False)
171
  gallery = gr.Gallery()
172
  button.click(predict_subset, [model_id, token], [gallery, plot])
173
-
 
 
 
 
 
 
 
 
 
174
  demo.launch(enable_queue=True)
 
11
  import backoff
12
  from functools import lru_cache
13
  from huggingface_hub import list_models, ModelFilter, login
14
+ import copy
15
 
16
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
17
 
 
128
 
129
 
130
  with gr.Blocks() as demo:
131
+ with gr.Tab("Random Image Gallery"):
132
  gr.Markdown(
133
+ """## Random image gallery
134
+ This tab allows you to explore images in your ARCH collection. You can refresh the images by clicking the refresh button.
135
+ **Please note** not all images will be displayed as some images may not available via the original URLS anymore."""
136
  )
137
  button = gr.Button("Refresh")
138
  gallery = gr.Gallery().style(grid=9, height="1400")
139
  button.click(return_random_sample, [], [gallery])
140
+ with gr.Tab("Image Search"):
141
  gr.Markdown(
142
+ """## Image search
143
  You can search for images by entering a search term and clicking the search button.
144
  You can also change the number of images to be returned.
145
  This model uses the [clip-ViT-B-16](https://huggingface.co/sentence-transformers/clip-ViT-B-16) model to embed your images and search term"""
 
149
  button = gr.Button("search")
150
  gallery = gr.Gallery().style(grid=3)
151
  button.click(get_nearest_k_examples, [text, k], [gallery])
152
+ # gr.Markdown(
153
+ # """### More info
154
+ # ![https://raw.githubusercontent.com/UKPLab/sentence-transformers/master/docs/img/ImageSearch.png](https://raw.githubusercontent.com/UKPLab/sentence-transformers/master/docs/img/ImageSearch.png)"""
155
+ # )
156
+
157
+ with gr.Tab("Image Classification Model Tester"):
 
 
 
 
 
158
  gr.Markdown(
159
+ """## Image classification model tester
160
+ You can use this to test out [image classification models](https://huggingface.co/models?pipeline_tag=image-classification) on the Hugging Face Hub:
161
+ - To use this tab you will need to have a Hugging Face account and a valid token.
162
+ - You can get a token from your [Hugging Face account page](https://huggingface.co/settings/token).
163
+ - Input this token into the token box and then input a valid image classification model id from the Hub. For example `microsoft/resnet-50`
164
+
165
+ This tab uses Hugging Face's [Inference API](https://huggingface.co/docs/api-inference/index) to make predictions. It will randomly select 10 images from your dataset and make predictions on them using your chosen model.
166
+ **Please note** the predictions will take some time since the model needs to be loaded for inference first. If you make a second batch of prediction using the same model the predictions should be quicker."""
167
  )
168
  token = gr.Textbox(label="token", type="password")
169
+ model_id = gr.Textbox(label="model_id", value="microsoft/resnet-50")
170
  button = gr.Button("predict")
171
  gr.Markdown("## Results")
172
  plot = gr.BarPlot(x="labels", y="freqs", width=600, height=400, vertical=False)
173
  gallery = gr.Gallery()
174
  button.click(predict_subset, [model_id, token], [gallery, plot])
175
+ with gr.Tab("Export to Label Studio format"):
176
+ gr.Markdown("""
177
+ ## Export to Label Studio format
178
+ This will export the current dataset to a csv file in Label Studio format. You can then import this into Label Studio to label your images.""")
179
+ dataset2 = copy.deepcopy(dataset)
180
+ dataset2 = dataset2.remove_columns('image')
181
+ dataset2 = dataset2.rename_column("url", "image")
182
+ csv = dataset2.to_csv("label_studio.csv")
183
+ csv_file = gr.File("label_studio.csv")
184
+ button.click(dataset.save_to_disk, [], [csv_file])
185
  demo.launch(enable_queue=True)