sanchit-gandhi HF staff commited on
Commit
03410c0
1 Parent(s): 8413cb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -24
app.py CHANGED
@@ -20,49 +20,62 @@ Options:
20
 
21
  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.
22
 
23
- Note: for this WIP demo only `sampling` is supported.
24
  """
25
 
26
- API_URL = os.getenv("API_URL")
27
 
28
  examples = [
29
- ['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:', 32, "sampling", False],
30
- ['A poem about the beauty of science by Alfred Edgar Brittle\nTitle: The Magic Craft\nIn the old times', 64, "sampling", False],
31
- ['استخراج العدد العاملي في لغة بايثون:', 32, "greedy", False],
32
- ["Pour déguster un ortolan, il faut tout d'abord", 32, "sampling", False],
33
- ['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 -', 32, "sampling", False],
34
- ['Estos ejemplos quitan vocales de las palabras\nEjemplos:\nhola - hl\nmanzana - mnzn\npapas - pps\nalacran - lcrn\npapa -', 32, "sampling", False],
35
- ["Question: If I put cheese into the fridge, will it melt?\nAnswer:", 32, "sampling", False],
36
- ["Math exercise - answers:\n34+10=44\n54+20=", 32, "greedy", False],
37
- ["Question: Where does the Greek Goddess Persephone spend half of the year when she is not with her mother?\nAnswer:", 32, "greedy", False],
38
- ["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:", 32, "greedy", False]
 
 
 
 
 
 
 
 
 
 
 
39
  ]
40
 
 
41
  def query(payload):
42
  print(payload)
43
  response = requests.post(API_URL, json=payload)
44
  print(response)
45
  return response.json()
46
-
 
47
  def inference(input_sentence, max_length, sample_or_greedy, raw_text=False):
48
  payload = {
49
- "prompt": input_sentence,
50
- "do_sample": True,
51
- #"max_new_tokens": max_length
52
  }
53
 
54
  data = query(
55
  payload
56
  )
57
-
58
  if raw_text:
59
- return None, data['generated_text'][0]
60
-
61
  width, height = 3326, 3326
62
  assets_path = "assets"
63
  font_mapping = {
64
  "latin characters (faster)": "DejaVuSans.ttf",
65
- "complete alphabet (slower)":"GoNotoCurrent.ttf"
66
  }
67
  working_dir = Path(__file__).parent.resolve()
68
  font_path = str(working_dir / font_mapping["complete alphabet (slower)"])
@@ -73,8 +86,8 @@ def inference(input_sentence, max_length, sample_or_greedy, raw_text=False):
73
  GENERATION_VAR: "#FF57A0",
74
  BOX_COMP: "#120F25",
75
  }
76
-
77
- new_string = data['generated_text'][0]
78
 
79
  _, img = main(
80
  input_sentence,
@@ -93,13 +106,13 @@ def inference(input_sentence, max_length, sample_or_greedy, raw_text=False):
93
 
94
 
95
  gr.Interface(
96
- inference,
97
  [
98
  gr.inputs.Textbox(label="Input"),
99
  gr.inputs.Radio([64], default=64, label="Tokens to generate"),
100
  gr.inputs.Radio(["sampling"], label="Sample or greedy", default="sampling"),
101
  gr.Checkbox(label="Just output raw text", value=True),
102
- ],
103
  ["image", "text"],
104
  examples=examples,
105
  # article=article,
 
20
 
21
  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.
22
 
23
+ Note: for this WIP demo only **sampling** is supported.
24
  """
25
 
26
+ API_URL = os.getenv("API_URL")
27
 
28
  examples = [
29
+ [
30
+ '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:',
31
+ 64, "sampling", False],
32
+ ['A poem about the beauty of science by Alfred Edgar Brittle\nTitle: The Magic Craft\nIn the old times', 64,
33
+ "sampling", False],
34
+ ['استخراج العدد العاملي في لغة بايثون:', 64, "greedy", False],
35
+ ["Pour déguster un ortolan, il faut tout d'abord", 64, "sampling", False],
36
+ [
37
+ '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 -',
38
+ 64, "sampling", False],
39
+ [
40
+ 'Estos ejemplos quitan vocales de las palabras\nEjemplos:\nhola - hl\nmanzana - mnzn\npapas - pps\nalacran - lcrn\npapa -',
41
+ 64, "sampling", False],
42
+ ["Question: If I put cheese into the fridge, will it melt?\nAnswer:", 64, "sampling", False],
43
+ ["Math exercise - answers:\n34+10=44\n54+20=", 64, "greedy", False],
44
+ [
45
+ "Question: Where does the Greek Goddess Persephone spend half of the year when she is not with her mother?\nAnswer:",
46
+ 64, "greedy", False],
47
+ [
48
+ "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:",
49
+ 64, "greedy", False]
50
  ]
51
 
52
+
53
  def query(payload):
54
  print(payload)
55
  response = requests.post(API_URL, json=payload)
56
  print(response)
57
  return response.json()
58
+
59
+
60
  def inference(input_sentence, max_length, sample_or_greedy, raw_text=False):
61
  payload = {
62
+ "prompt": input_sentence,
63
+ "do_sample": True,
64
+ # "max_new_tokens": max_length
65
  }
66
 
67
  data = query(
68
  payload
69
  )
70
+
71
  if raw_text:
72
+ return None, data['generated_text']
73
+
74
  width, height = 3326, 3326
75
  assets_path = "assets"
76
  font_mapping = {
77
  "latin characters (faster)": "DejaVuSans.ttf",
78
+ "complete alphabet (slower)": "GoNotoCurrent.ttf"
79
  }
80
  working_dir = Path(__file__).parent.resolve()
81
  font_path = str(working_dir / font_mapping["complete alphabet (slower)"])
 
86
  GENERATION_VAR: "#FF57A0",
87
  BOX_COMP: "#120F25",
88
  }
89
+
90
+ new_string = data['generated_text']
91
 
92
  _, img = main(
93
  input_sentence,
 
106
 
107
 
108
  gr.Interface(
109
+ inference,
110
  [
111
  gr.inputs.Textbox(label="Input"),
112
  gr.inputs.Radio([64], default=64, label="Tokens to generate"),
113
  gr.inputs.Radio(["sampling"], label="Sample or greedy", default="sampling"),
114
  gr.Checkbox(label="Just output raw text", value=True),
115
+ ],
116
  ["image", "text"],
117
  examples=examples,
118
  # article=article,