anugrahap commited on
Commit
93cec36
·
1 Parent(s): 195bb6b

rollback to the stable of Version 2.0 app

Browse files
Files changed (1) hide show
  1. app.py +4 -67
app.py CHANGED
@@ -66,53 +66,6 @@ def single_generation(text,min_length,max_length,temperature,top_k,top_p,num_bea
66
  else:
67
  return error_unknown
68
 
69
- # create the decoder parameter to generate the text
70
- def multiple_generation(text,min_length,max_length,temperature,top_k,top_p,num_beams,repetition_penalty,do_sample):
71
- # create local variable for error parameter
72
- error_rep=ValueError(f"ERROR: repetition penalty cannot be lower than one! Given rep penalty = {repetition_penalty}")
73
- error_temp=ValueError(f"ERROR: temperature cannot be zero or lower! Given temperature = {temperature}")
74
- error_minmax=ValueError(f"ERROR: min length must be lower than or equal to max length! Given min length = {min_length}")
75
- error_numbeams_type=TypeError(f"ERROR: number of beams must be an integer not {type(num_beams)}")
76
- error_topk_type=TypeError(f"ERROR: top k must be an integer not {type(top_k)}")
77
- error_minmax_type=TypeError(f"ERROR: min length and max length must be an integer not {type(min_length)} and {type(max_length)}")
78
- error_empty=ValueError("ERROR: Input Text cannot be empty!")
79
- error_unknown=TypeError("Unknown Error.")
80
-
81
- if text != '':
82
- if type(min_length) == int and type(max_length) == int:
83
- if type(top_k) == int:
84
- if type(num_beams) == int:
85
- if min_length <= max_length:
86
- if temperature > 0:
87
- if repetition_penalty >= 1:
88
- result = generator(text,
89
- min_length=min_length,
90
- max_length=max_length,
91
- temperature=temperature,
92
- top_k=top_k,
93
- top_p=top_p,
94
- num_beams=num_beams,
95
- repetition_penalty=repetition_penalty,
96
- do_sample=do_sample,
97
- no_repeat_ngram_size=2,
98
- num_return_sequences=3)
99
- return result[0]["generated_text"], result[1]["generated_text"], result[2]["generated_text"],
100
- elif repetition_penalty < 1:
101
- return error_rep,error_rep,error_rep
102
- elif temperature <= 0:
103
- return error_temp,error_temp,error_temp
104
- elif min_length > max_length:
105
- return error_minmax,error_minmax,error_minmax
106
- elif type(num_beams) != int:
107
- return error_numbeams_type,error_numbeams_type,error_numbeams_type
108
- elif type(top_k) != int:
109
- return error_topk_type,error_topk_type,error_topk_type
110
- elif type(min_length) != int or type(max_length) != int:
111
- return error_minmax_type,error_minmax_type,error_minmax_type
112
- elif text == '':
113
- return error_empty,error_empty,error_empty
114
- else:
115
- return error_unknown,error_unknown,error_unknown
116
 
117
  # create the variable needed for the gradio app
118
  forinput=[gr.Textbox(lines=5, label="Input Text"),
@@ -125,10 +78,7 @@ forinput=[gr.Textbox(lines=5, label="Input Text"),
125
  gr.Number(label="Repetition Penalty", value=2.0),
126
  gr.Dropdown(label="Do Sample?", choices=[True,False], value=True, multiselect=False)]
127
 
128
- output1=gr.Textbox(lines=5, max_lines=50, label="Generated Text with Greedy/Beam Search Decoding")
129
- output2=[gr.Textbox(lines=5, max_lines=50, label="#1 Generated Text with Greedy/Beam Search Decoding"),
130
- gr.Textbox(lines=5, max_lines=50, label="#2 Generated Text with Greedy/Beam Search Decoding"),
131
- gr.Textbox(lines=5, max_lines=50, label="#3 Generated Text with Greedy/Beam Search Decoding")]
132
 
133
  examples = [
134
  ["Indonesia adalah negara kepulauan", 10, 30, 1.0, 25, 0.92, 5, 2.0, True],
@@ -173,22 +123,10 @@ article = """<p style='text-align: center'>
173
  """
174
 
175
  # using gradio interfaces
176
- app1 = gr.Interface(
177
  fn=single_generation,
178
  inputs=forinput,
179
- outputs=output1,
180
- examples=examples,
181
- title=title,
182
- description=description,
183
- article=article,
184
- allow_flagging='manual',
185
- flagging_options=['Well Performed', 'Inappropriate Word Selection', 'Wordy', 'Strange Word', 'Others'],
186
- flagging_callback=hf_writer)
187
-
188
- app2 = gr.Interface(
189
- fn=multiple_generation,
190
- inputs=forinput,
191
- outputs=output2,
192
  examples=examples,
193
  title=title,
194
  description=description,
@@ -197,7 +135,6 @@ app2 = gr.Interface(
197
  flagging_options=['Well Performed', 'Inappropriate Word Selection', 'Wordy', 'Strange Word', 'Others'],
198
  flagging_callback=hf_writer)
199
 
200
- final_app = gr.TabbedInterface([app1,app2],["Single Generation", "Multiple Generation (high computation)"])
201
 
202
  if __name__=='__main__':
203
- final_app.launch()
 
66
  else:
67
  return error_unknown
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  # create the variable needed for the gradio app
71
  forinput=[gr.Textbox(lines=5, label="Input Text"),
 
78
  gr.Number(label="Repetition Penalty", value=2.0),
79
  gr.Dropdown(label="Do Sample?", choices=[True,False], value=True, multiselect=False)]
80
 
81
+ foroutput=gr.Textbox(lines=5, max_lines=50, label="Generated Text with Greedy/Beam Search Decoding")
 
 
 
82
 
83
  examples = [
84
  ["Indonesia adalah negara kepulauan", 10, 30, 1.0, 25, 0.92, 5, 2.0, True],
 
123
  """
124
 
125
  # using gradio interfaces
126
+ app = gr.Interface(
127
  fn=single_generation,
128
  inputs=forinput,
129
+ outputs=foroutput,
 
 
 
 
 
 
 
 
 
 
 
 
130
  examples=examples,
131
  title=title,
132
  description=description,
 
135
  flagging_options=['Well Performed', 'Inappropriate Word Selection', 'Wordy', 'Strange Word', 'Others'],
136
  flagging_callback=hf_writer)
137
 
 
138
 
139
  if __name__=='__main__':
140
+ app.launch()