sanchit-gandhi HF staff commited on
Commit
7011f7b
1 Parent(s): 7776945

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -30
app.py CHANGED
@@ -1,7 +1,5 @@
1
  import gradio as gr
2
- import re
3
  import requests
4
- import json
5
  import os
6
  from screenshot import BG_COMP, BOX_COMP, GENERATION_VAR, PROMPT_VAR, main
7
  from pathlib import Path
@@ -18,44 +16,36 @@ Options:
18
  - greedy: accurate completions (may be more boring or have repetitions)
19
  """
20
 
21
- wip_description = """Gradio Demo for JAX / Flax BLOOM. The 176B BLOOM model running on a TPU v3-256 pod, with 2D model parallelism and custom mesh axes.
22
 
23
-
24
- Note: rendering of the screenshot is currently not optimised. To experience the true speed of JAX / Flax, tick 'just output raw text'.
25
-
26
- Tips:
27
- - Do NOT talk to BLOOM as an entity, it's not a chatbot but a webpage/blog/article completion model.
28
- - For the best results: MIMIC a few sentences of a webpage similar to the content you want to generate.
29
- Start a paragraph as if YOU were writing a blog, webpage, math post, coding article and BLOOM will generate a coherent follow-up. Longer prompts usually give more interesting results.
30
- Options:
31
- - sampling: imaginative completions (may be not super accurate e.g. math/history)
32
- - greedy: accurate completions (may be more boring or have repetitions)
33
  """
34
 
35
  API_URL = os.getenv("API_URL")
36
 
37
  examples = [
38
- [
39
- 'A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses the word whatpu is: We were traveling in Africa and we saw these very cute whatpus. To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses the word farduddle is:',
40
  64, "sampling", True],
41
  ['A poem about the beauty of science by Alfred Edgar Brittle\nTitle: The Magic Craft\nIn the old times', 64,
42
  "sampling", True],
43
- ['استخراج العدد العاملي في لغة بايثون:', 64, "sampling", True],
44
  ["Pour déguster un ortolan, il faut tout d'abord", 64, "sampling", True],
45
- [
46
- 'Traduce español de España a español de Argentina\nEl coche es rojo - el auto es rojo\nEl ordenador es nuevo - la computadora es nueva\nel boligrafo es negro -',
47
  64, "sampling", True],
48
- [
49
- 'Estos ejemplos quitan vocales de las palabras\nEjemplos:\nhola - hl\nmanzana - mnzn\npapas - pps\nalacran - lcrn\npapa -',
50
  64, "sampling", True],
51
- ["Question: If I put cheese into the fridge, will it melt?\nAnswer:", 64, "sampling", True],
52
  ["Math exercise - answers:\n34+10=44\n54+20=", 64, "sampling", True],
53
- [
54
- "Question: Where does the Greek Goddess Persephone spend half of the year when she is not with her mother?\nAnswer:",
55
  64, "sampling", True],
56
- [
57
- "spelling test answers.\nWhat are the letters in « language »?\nAnswer: l-a-n-g-u-a-g-e\nWhat are the letters in « Romanian »?\nAnswer:",
58
  64, "sampling", True]
 
 
59
  ]
60
 
61
 
@@ -67,9 +57,10 @@ def query(payload):
67
 
68
 
69
  def inference(input_sentence, max_length, sample_or_greedy, raw_text=True):
 
70
  payload = {
71
  "inputs": input_sentence,
72
- "do_sample": True,
73
  # "max_new_tokens": max_length
74
  }
75
 
@@ -78,7 +69,7 @@ def inference(input_sentence, max_length, sample_or_greedy, raw_text=True):
78
  )
79
 
80
  if raw_text:
81
- return None, data[0]['generated_text'][0]
82
 
83
  width, height = 3326, 3326
84
  assets_path = "assets"
@@ -97,7 +88,7 @@ def inference(input_sentence, max_length, sample_or_greedy, raw_text=True):
97
  }
98
 
99
  # TODO: fix screenshot
100
- new_string = data[0]['generated_text'][0].split(input_sentence, 1)[1]
101
 
102
  _, img = main(
103
  input_sentence,
@@ -112,7 +103,7 @@ def inference(input_sentence, max_length, sample_or_greedy, raw_text=True):
112
  init_font_size=142,
113
  right_align=False,
114
  )
115
- return img, data[0]['generated_text'][0]
116
 
117
 
118
  gr.Interface(
@@ -120,7 +111,7 @@ gr.Interface(
120
  [
121
  gr.inputs.Textbox(label="Input"),
122
  gr.inputs.Radio([64], default=64, label="Tokens to generate"),
123
- gr.inputs.Radio(["sampling"], label="Sample or greedy", default="sampling"),
124
  gr.Checkbox(label="Just output raw text", value=True),
125
  ],
126
  ["image", "text"],
 
1
  import gradio as gr
 
2
  import requests
 
3
  import os
4
  from screenshot import BG_COMP, BOX_COMP, GENERATION_VAR, PROMPT_VAR, main
5
  from pathlib import Path
 
16
  - greedy: accurate completions (may be more boring or have repetitions)
17
  """
18
 
19
+ wip_description = """JAX / Flax Gradio Demo for BLOOM. The 176B BLOOM model running on a TPU v3-256 pod, with 2D model parallelism and custom mesh axes.
20
 
21
+ Note:
22
+ 1. For this WIP demo, only **sampling** is supported.
23
+ 2. Rendering of the screenshot is currently not optimised. To experience the true speed of JAX / Flax, tick 'just output raw text'.
 
 
 
 
 
 
 
24
  """
25
 
26
  API_URL = os.getenv("API_URL")
27
 
28
  examples = [
29
+
30
+ ['To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses the word farduddle is:',
31
  64, "sampling", True],
32
  ['A poem about the beauty of science by Alfred Edgar Brittle\nTitle: The Magic Craft\nIn the old times', 64,
33
  "sampling", True],
34
+ ['استخراج العدد العاملي في لغة بايثون:', 64, "greedy", True],
35
  ["Pour déguster un ortolan, il faut tout d'abord", 64, "sampling", True],
36
+ ['Traduce español de España a español de Argentina\nEl coche es rojo - el auto es rojo\nEl ordenador es nuevo - la computadora es nueva\nel boligrafo es negro -',
 
37
  64, "sampling", True],
38
+ ['Estos ejemplos quitan vocales de las palabras\nEjemplos:\nhola - hl\nmanzana - mnzn\npapas - pps\nalacran - lcrn\npapa -',
 
39
  64, "sampling", True],
40
+ ["Question: If I put cheese into the fridge, will it melt?\nAnswer:", 64, "greedy", True],
41
  ["Math exercise - answers:\n34+10=44\n54+20=", 64, "sampling", True],
42
+ ["Python code to compute the factorial of a given number:", 64, "greedy", True]
43
+ ["Question: Where does the Greek Goddess Persephone spend half of the year when she is not with her mother?\nAnswer:",
44
  64, "sampling", True],
45
+ ["spelling test answers.\nWhat are the letters in « language »?\nAnswer: l-a-n-g-u-a-g-e\nWhat are the letters in « Romanian »?\nAnswer:",
 
46
  64, "sampling", True]
47
+ ['A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses the word whatpu is:',
48
+ 64, "sampling", True],
49
  ]
50
 
51
 
 
57
 
58
 
59
  def inference(input_sentence, max_length, sample_or_greedy, raw_text=True):
60
+ do_sample = sample_or_greedy == "sampling"
61
  payload = {
62
  "inputs": input_sentence,
63
+ "do_sample": do_sample,
64
  # "max_new_tokens": max_length
65
  }
66
 
 
69
  )
70
 
71
  if raw_text:
72
+ return None, data['generated_text'][0]
73
 
74
  width, height = 3326, 3326
75
  assets_path = "assets"
 
88
  }
89
 
90
  # TODO: fix screenshot
91
+ new_string = data['generated_text'][0].split(input_sentence, 1)[1]
92
 
93
  _, img = main(
94
  input_sentence,
 
103
  init_font_size=142,
104
  right_align=False,
105
  )
106
+ return img, data['generated_text'][0][0]
107
 
108
 
109
  gr.Interface(
 
111
  [
112
  gr.inputs.Textbox(label="Input"),
113
  gr.inputs.Radio([64], default=64, label="Tokens to generate"),
114
+ gr.inputs.Radio(["sampling", "greedy"], label="Sample or greedy", default="sampling"),
115
  gr.Checkbox(label="Just output raw text", value=True),
116
  ],
117
  ["image", "text"],