sasha HF Staff commited on
Commit
657f29b
·
1 Parent(s): ab7a42f

trying like this

Browse files
Files changed (1) hide show
  1. app.py +4 -21
app.py CHANGED
@@ -3,9 +3,7 @@ import gradio as gr
3
  from datasets import load_dataset
4
  from transformers import AutoModel, AutoFeatureExtractor
5
  import wikipedia
6
- from platform import python_version
7
 
8
- print(python_version())
9
 
10
  # Only runs once when the script is first run.
11
  with open("butts_1024_new.pickle", "rb") as handle:
@@ -29,23 +27,9 @@ def query(image, top_k=1):
29
  results = index.query(embedding, k=top_k)
30
  inx = results[0][0].tolist()
31
  logits = results[1][0].tolist()
32
- images = ds.select(inx)["image"]
33
- captions = ds.select(inx)["name"]
34
- images_with_captions = [(i, c) for i, c in zip(images, captions)]
35
- labels_with_probs = dict(zip(captions, logits))
36
- labels_with_probs = {k: 1 - v for k, v in labels_with_probs.items()}
37
- try:
38
- description = wikipedia.summary(captions[0], sentences=1)
39
- description = "### " + description
40
- url = wikipedia.page(captions[0]).url
41
- url = " You can learn more about your butterfly [here](" + str(url) + ")!"
42
- description = description + url
43
- except:
44
- description = "### Butterflies are insects in the order Lepidoptera, which also includes moths. Adult butterflies have large, often brightly coloured wings."
45
- url = "https://en.wikipedia.org/wiki/Butterfly"
46
- url = " You can learn more about butterflies [here](" + str(url) + ")!"
47
- description = description + url
48
- return images_with_captions, labels_with_probs, description
49
 
50
 
51
  with gr.Blocks() as demo:
@@ -61,7 +45,6 @@ with gr.Blocks() as demo:
61
 
62
  with gr.Column(scale=2):
63
  outputs = gr.Gallery(rows=1)
64
- labels = gr.Label()
65
 
66
  gr.Markdown("### Image Examples")
67
  gr.Examples(
@@ -71,6 +54,6 @@ with gr.Blocks() as demo:
71
  fn=query,
72
  cache_examples=True,
73
  )
74
- btn.click(query, inputs, [outputs, labels, description])
75
 
76
  demo.launch()
 
3
  from datasets import load_dataset
4
  from transformers import AutoModel, AutoFeatureExtractor
5
  import wikipedia
 
6
 
 
7
 
8
  # Only runs once when the script is first run.
9
  with open("butts_1024_new.pickle", "rb") as handle:
 
27
  results = index.query(embedding, k=top_k)
28
  inx = results[0][0].tolist()
29
  logits = results[1][0].tolist()
30
+ butterfly = ds.select(inx)["image"][0]
31
+ butterfly.show()
32
+ return butterfly
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
 
35
  with gr.Blocks() as demo:
 
45
 
46
  with gr.Column(scale=2):
47
  outputs = gr.Gallery(rows=1)
 
48
 
49
  gr.Markdown("### Image Examples")
50
  gr.Examples(
 
54
  fn=query,
55
  cache_examples=True,
56
  )
57
+ btn.click(query, inputs, butterfly)
58
 
59
  demo.launch()