Ceshine Lee commited on
Commit
3084017
1 Parent(s): d11e70d

Add a temperature option

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -10,21 +10,28 @@ ENDPOINT = (
10
  )
11
 
12
 
13
- def paraphrase(source_text):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  res = requests.post(
15
  ENDPOINT,
16
  headers={"Authorization": f"Bearer {os.environ['TOKEN']}"},
17
  data=json.dumps(
18
  {
19
  "inputs": "paraphrase: " + source_text,
20
- "parameters": {
21
- # "do_sample": True,
22
- "temperature": 1.5,
23
- "top_k": 5,
24
- "num_beams": 10,
25
- "num_return_sequences": 10,
26
- "max_length": 100,
27
- },
28
  }
29
  ),
30
  )
@@ -45,13 +52,16 @@ def paraphrase(source_text):
45
 
46
  interface = gr.Interface(
47
  fn=paraphrase,
48
- inputs=inputs.Textbox(label="Input"),
 
 
 
49
  outputs=outputs.Textbox(label="Generated text:"),
50
  title="T5 Sentence Paraphraser",
51
- description="A paraphrasing model trained on PAWS and Quora datasets",
52
  examples=[
53
- ["I bought a ticket from London to New York."],
54
- ["Weh Seun spends 14 hours a week doing housework."],
55
  ],
56
  )
57
 
 
10
  )
11
 
12
 
13
+ def paraphrase(source_text: str, temperature: float):
14
+ if temperature > 0:
15
+ params = {
16
+ "do_sample": True,
17
+ "temperature": temperature,
18
+ "top_k": 5,
19
+ "num_return_sequences": 10,
20
+ "max_length": 100
21
+ }
22
+ else:
23
+ params = {
24
+ "num_beams": 10,
25
+ "num_return_sequences": 10,
26
+ "max_length": 100
27
+ }
28
  res = requests.post(
29
  ENDPOINT,
30
  headers={"Authorization": f"Bearer {os.environ['TOKEN']}"},
31
  data=json.dumps(
32
  {
33
  "inputs": "paraphrase: " + source_text,
34
+ "parameters": params,
 
 
 
 
 
 
 
35
  }
36
  ),
37
  )
 
52
 
53
  interface = gr.Interface(
54
  fn=paraphrase,
55
+ inputs=[
56
+ inputs.Textbox(label="Source text"),
57
+ inputs.Number(default=0.0, label="Temperature (0 -> disable sampling and use beam search)"),
58
+ ],
59
  outputs=outputs.Textbox(label="Generated text:"),
60
  title="T5 Sentence Paraphraser",
61
+ description="A paraphrasing model trained on PAWS and Quora datasets.",
62
  examples=[
63
+ ["I bought a ticket from London to New York.", 0],
64
+ ["Weh Seun spends 14 hours a week doing housework.", 1.2],
65
  ],
66
  )
67