Daniel Fried commited on
Commit
422733b
1 Parent(s): 0bdc941

update examples

Browse files
Files changed (2) hide show
  1. app.py +8 -0
  2. static/index.html +25 -54
app.py CHANGED
@@ -9,6 +9,8 @@ import pprint
9
  from huggingface_hub import Repository
10
  from text_generation import Client
11
 
 
 
12
  PORT = 7860
13
 
14
  # TODO: implement maximum length (currently, each iteration is limited by the slider-specified max length, but this can be iterated, or long code entered into the editor, to get really long documents
@@ -109,6 +111,9 @@ async def generate_maybe(info: str):
109
  else:
110
  message = ''
111
  return {'result': 'success', 'type': 'generate', 'prompt': prompt, 'text': generation['text'], 'message': message}
 
 
 
112
  except Exception as e:
113
  traceback.print_exception(*sys.exc_info())
114
  return {'result': 'error', 'type': 'generate', 'prompt': prompt, 'message': f'Error: {e}.'}
@@ -134,6 +139,9 @@ async def infill_maybe(info: str):
134
  else:
135
  generation['message'] = ''
136
  return generation
 
 
 
137
  except Exception as e:
138
  traceback.print_exception(*sys.exc_info())
139
  return {'result': 'error', 'type': 'infill', 'message': f'Error: {e}.'}
 
9
  from huggingface_hub import Repository
10
  from text_generation import Client
11
 
12
+ from requests.exceptions import ReadTimeout
13
+
14
  PORT = 7860
15
 
16
  # TODO: implement maximum length (currently, each iteration is limited by the slider-specified max length, but this can be iterated, or long code entered into the editor, to get really long documents
 
111
  else:
112
  message = ''
113
  return {'result': 'success', 'type': 'generate', 'prompt': prompt, 'text': generation['text'], 'message': message}
114
+ except ReadTimeout as e:
115
+ print(e)
116
+ return {'result': 'error', 'type': 'generate', 'prompt': prompt, 'message': f'Request timed out.'}
117
  except Exception as e:
118
  traceback.print_exception(*sys.exc_info())
119
  return {'result': 'error', 'type': 'generate', 'prompt': prompt, 'message': f'Error: {e}.'}
 
139
  else:
140
  generation['message'] = ''
141
  return generation
142
+ except ReadTimeout as e:
143
+ print(e)
144
+ return {'result': 'error', 'type': 'generate', 'prompt': prompt, 'message': f'Request timed out.'}
145
  except Exception as e:
146
  traceback.print_exception(*sys.exc_info())
147
  return {'result': 'error', 'type': 'infill', 'message': f'Error: {e}.'}
static/index.html CHANGED
@@ -135,17 +135,15 @@ label {
135
  <div id="examples-extend">
136
  <span class="softspan">Extend Examples:</span>
137
  <br>
138
- <span class="softspan"><a href='javascript:select_example("hello-world");'>Hello World</a></span>
139
- <span class="softspan"><a href='javascript:select_example("fibonacci");'>Fibonacci</a></span>
140
- <span class="softspan"><a href='javascript:select_example("typing");'>Typing</a></span>
141
- <span class="softspan"><a href='javascript:select_example("complex-numbers");'>Complex Numbers</a></span>
142
  </div>
143
  <div id="examples-infill">
144
  <span class="softspan">Infill Examples:</span>
145
  <br>
146
  <span class="softspan"><a href='javascript:select_example("type-pred");'>Type Prediction</a></span>
147
- <span class="softspan"><a href='javascript:select_example("docstring-1");'>Docstring Generation 1</a></span>
148
- <span class="softspan"><a href='javascript:select_example("docstring-2");'>Docstring Generation 2</a></span>
149
  </div>
150
  </div>
151
  <div class="card" id="controls">
@@ -226,8 +224,7 @@ var Range = require("ace/range").Range;
226
  // examples for the user
227
  var EXAMPLES = {
228
  "type-pred": {
229
- "prompt":
230
- `def count_words(filename: str) -> <infill>
231
  """Count the number of occurrences of each word in the file."""
232
  with open(filename, 'r') as f:
233
  word_counts = {}
@@ -243,9 +240,8 @@ var EXAMPLES = {
243
  "temperature": 0.2,
244
  "mode": "python"
245
  },
246
- "docstring-1": {
247
- "prompt":
248
- `def _minimize_in_graph(build_loss_fn, num_steps=200, optimizer=None):
249
  """
250
  <infill>
251
  """
@@ -263,61 +259,34 @@ var EXAMPLES = {
263
  loop_vars=[tf.constant(0)],
264
  return_same_structure=True)[0]
265
  return minimize_op`,
266
- "length": 64,
267
- "temperature": 0.3,
268
  "mode": "python",
269
  },
270
- "docstring-2": {
271
- "prompt":
272
- `def count_words(filename: str) -> Dict[str, int]:
273
- """<infill>
274
- """
275
- with open(filename, 'r') as f:
276
- word_counts = {}
277
- for line in f:
278
- for word in line.split():
279
- if word in word_counts:
280
- word_counts[word] = 1
281
- else:
282
- word_counts[word] = 1
283
- return word_counts
284
- `,
285
- "length": 32,
286
- "temperature": 0.2,
287
- "mode": "python"
288
- },
289
  // extend examples
290
- "hello-world": {
291
- "prompt": "def print_hello_world():",
 
 
292
  "length": 64,
293
  "temperature": 0.2,
294
  "mode": "python"
295
  },
296
- "fibonacci": {
297
  "prompt":
298
- `def fibonacci(n: int) -> int:
299
- """ Compute the n-th Fibonacci number. """`,
300
  "temperature": 0.2,
301
  "length": 64,
302
- "mode": "python"
303
  },
304
- "typing": {
305
- "prompt":
306
- `from typing import List, Tuple
307
-
308
- def sum_and_product(numbers: List[int]) -> Tuple[int, int]:
309
- """ Return the sum and the product of the integers in the list as a tuple. Here is the answer of the exercise"""`,
310
- "temperature": 0.2,
311
- "length": 64,
312
- "mode": "python"
313
- },
314
- "complex-numbers": {
315
- "prompt":
316
- `class ComplexNumbers:`,
317
- "temperature": 0.2,
318
  "length": 128,
319
- "mode": "python"
320
- }
321
  };
322
 
323
  var editor = ace.edit("editor");
@@ -516,6 +485,8 @@ function make_generate_listener(url) {
516
  }
517
  } else {
518
  console.log("error");
 
 
519
  set_text(receive_data["text"])
520
  $("#error").text(receive_data["message"]);
521
  }
 
135
  <div id="examples-extend">
136
  <span class="softspan">Extend Examples:</span>
137
  <br>
138
+ <span class="softspan"><a href='javascript:select_example("logistic-regression");'>Logistic Regression (Python)</a></span>
139
+ <span class="softspan"><a href='javascript:select_example("array");'>Arrays (JS)</a></span>
140
+ <span class="softspan"><a href='javascript:select_example("metadata");'>Metadata-Conditioning (JS)</a></span>
 
141
  </div>
142
  <div id="examples-infill">
143
  <span class="softspan">Infill Examples:</span>
144
  <br>
145
  <span class="softspan"><a href='javascript:select_example("type-pred");'>Type Prediction</a></span>
146
+ <span class="softspan"><a href='javascript:select_example("docstring");'>Docstring Generation</a></span>
 
147
  </div>
148
  </div>
149
  <div class="card" id="controls">
 
224
  // examples for the user
225
  var EXAMPLES = {
226
  "type-pred": {
227
+ "prompt": `def count_words(filename: str) -> <infill>
 
228
  """Count the number of occurrences of each word in the file."""
229
  with open(filename, 'r') as f:
230
  word_counts = {}
 
240
  "temperature": 0.2,
241
  "mode": "python"
242
  },
243
+ "docstring": {
244
+ "prompt": `def _minimize_in_graph(build_loss_fn, num_steps=200, optimizer=None):
 
245
  """
246
  <infill>
247
  """
 
259
  loop_vars=[tf.constant(0)],
260
  return_same_structure=True)[0]
261
  return minimize_op`,
262
+ "length": 128,
263
+ "temperature": 0.2,
264
  "mode": "python",
265
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  // extend examples
267
+ "logistic-regression": {
268
+ "prompt": `X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.1)
269
+
270
+ # Train a logistic regression model, predict the labels on the test set and compute the accuracy score`,
271
  "length": 64,
272
  "temperature": 0.2,
273
  "mode": "python"
274
  },
275
+ "array": {
276
  "prompt":
277
+ `// Returns every other value in the array as a new array.
278
+ function everyOther(arr) {`,
279
  "temperature": 0.2,
280
  "length": 64,
281
+ "mode": "javascript"
282
  },
283
+ "metadata": {
284
+ "prompt": `<filename>start_server.js<gh_stars>100-1000
285
+ `,
286
+ "temperature": 0.6,
 
 
 
 
 
 
 
 
 
 
287
  "length": 128,
288
+ "mode": "javascript"
289
+ },
290
  };
291
 
292
  var editor = ace.edit("editor");
 
485
  }
486
  } else {
487
  console.log("error");
488
+ console.log("data:");
489
+ console.log(receive_data);
490
  set_text(receive_data["text"])
491
  $("#error").text(receive_data["message"]);
492
  }