timaaos2 commited on
Commit
8f13478
1 Parent(s): 909674f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -12
app.py CHANGED
@@ -3,18 +3,9 @@ from gpt import get_model
3
 
4
 
5
  model_small, tokenizer_small = get_model("gpt2")
6
- model_large, tokenizer_large = get_model("gpt2-large")
7
 
8
  def predict(inp, model_type):
9
- if model_type == "gpt2-large":
10
- model, tokenizer = model_large, tokenizer_large
11
- input_ids = tokenizer.encode("user:"+inp+"\nai:", return_tensors='tf')
12
- beam_output = model.generate(input_ids, max_length=60, num_beams=5,
13
- no_repeat_ngram_size=2,
14
- early_stopping=True)
15
- output = tokenizer.decode(beam_output[0], skip_special_tokens=True,
16
- clean_up_tokenization_spaces=True)
17
- else:
18
  model, tokenizer = model_small, tokenizer_small
19
  input_ids = tokenizer.encode("user:"+inp+"\nai:", return_tensors='tf')
20
  beam_output = model.generate(input_ids, max_length=180, num_beams=5,
@@ -28,11 +19,11 @@ def predict(inp, model_type):
28
 
29
 
30
  INPUTS = [gradio.inputs.Textbox(lines=2, label="Input Text"),
31
- gradio.inputs.Radio(choices=["gpt2-small", "gpt2-large"],
32
  label="Model Size")]
33
  OUTPUTS = gradio.outputs.Textbox()
34
  examples = [
35
- ["The toughest thing about software engineering is", "gpt2-large"],
36
  ["Is this the real life? Is this just fantasy?", "gpt2-small"]
37
  ]
38
  INTERFACE = gradio.Interface(fn=predict, inputs=INPUTS, outputs=OUTPUTS, title="Chat GPT-2",
3
 
4
 
5
  model_small, tokenizer_small = get_model("gpt2")
 
6
 
7
  def predict(inp, model_type):
8
+ if model_type == "gpt2":
 
 
 
 
 
 
 
 
9
  model, tokenizer = model_small, tokenizer_small
10
  input_ids = tokenizer.encode("user:"+inp+"\nai:", return_tensors='tf')
11
  beam_output = model.generate(input_ids, max_length=180, num_beams=5,
19
 
20
 
21
  INPUTS = [gradio.inputs.Textbox(lines=2, label="Input Text"),
22
+ gradio.inputs.Radio(choices=["gpt2-small"],
23
  label="Model Size")]
24
  OUTPUTS = gradio.outputs.Textbox()
25
  examples = [
26
+ ["The toughest thing about software engineering is", "gpt2-small"],
27
  ["Is this the real life? Is this just fantasy?", "gpt2-small"]
28
  ]
29
  INTERFACE = gradio.Interface(fn=predict, inputs=INPUTS, outputs=OUTPUTS, title="Chat GPT-2",