yirmibesogluz commited on
Commit
cce4feb
1 Parent(s): 496bd7a

Added news title generation

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -109,6 +109,14 @@ def summarize(input, model_choice, max_new_tokens, length_penalty, no_repeat_ngr
109
  summarization_model = pipeline(model=model_mapping[model_choice], device=0)
110
  return summarization_model(input, max_new_tokens = max_new_tokens, length_penalty=length_penalty, no_repeat_ngram_size=no_repeat_ngram_size)[0]["generated_text"]
111
 
 
 
 
 
 
 
 
 
112
  @spaces.GPU
113
  def categorize(input):
114
  ttc = pipeline(model="boun-tabi-LMG/turna_classification_ttc4900", device=0)
@@ -241,6 +249,30 @@ with gr.Blocks(theme="abidlabs/Lime") as demo:
241
  sum_submit.click(summarize, inputs=[sum_input, sum_choice, max_new_tokens, length_penalty, no_repeat_ngram_size], outputs=sum_output)
242
  sum_examples = gr.Examples(examples = long_text, inputs = [sum_input, sum_choice, max_new_tokens, length_penalty, no_repeat_ngram_size], outputs=sum_output, fn=summarize)
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  with gr.Tab("Text Generation"):
245
  gr.Markdown("Pre-trained TURNA. Enter text to start generating.")
246
  with gr.Column():
 
109
  summarization_model = pipeline(model=model_mapping[model_choice], device=0)
110
  return summarization_model(input, max_new_tokens = max_new_tokens, length_penalty=length_penalty, no_repeat_ngram_size=no_repeat_ngram_size)[0]["generated_text"]
111
 
112
+ @spaces.GPU
113
+ def generate_title(input, model_choice, max_new_tokens, length_penalty, no_repeat_ngram_size):
114
+ model_mapping = {"turna_title_generation_tr_news": "boun-tabi-LMG/turna_title_generation_tr_news",
115
+ "turna_title_generation_mlsum": "boun-tabi-LMG/turna_title_generation_mlsum"}
116
+ summarization_model = pipeline(model=model_mapping[model_choice], device=0)
117
+ return summarization_model(input, max_new_tokens = max_new_tokens, length_penalty=length_penalty, no_repeat_ngram_size=no_repeat_ngram_size)[0]["generated_text"]
118
+
119
+
120
  @spaces.GPU
121
  def categorize(input):
122
  ttc = pipeline(model="boun-tabi-LMG/turna_classification_ttc4900", device=0)
 
249
  sum_submit.click(summarize, inputs=[sum_input, sum_choice, max_new_tokens, length_penalty, no_repeat_ngram_size], outputs=sum_output)
250
  sum_examples = gr.Examples(examples = long_text, inputs = [sum_input, sum_choice, max_new_tokens, length_penalty, no_repeat_ngram_size], outputs=sum_output, fn=summarize)
251
 
252
+ with gr.Tab("Title Generation"):
253
+ gr.Markdown("TURNA fine-tuned on news title generation. Enter news text to generate a title.")
254
+ with gr.Column():
255
+ with gr.Row():
256
+ with gr.Column():
257
+ title_choice = gr.Radio(choices = ["turna_title_generation_tr_news", "turna_title_generation_mlsum"], label ="Model", value="turna_title_generation_tr_news")
258
+ with gr.Accordion("Advanced Generation Parameters"):
259
+ max_new_tokens = gr.Slider(label = "Maximum length",
260
+ minimum = 0,
261
+ maximum = 64,
262
+ value = 64)
263
+ length_penalty = gr.Slider(label = "Length penalty",
264
+ minimum = -10,
265
+ maximum = 10,
266
+ value=2.0)
267
+ no_repeat_ngram_size =gr.Slider(label="No Repeat N-Gram Size", minimum=0,value=3,)
268
+ with gr.Column():
269
+ title_input = gr.Textbox(label = "News Title Generation Input")
270
+ title_submit = gr.Button()
271
+ title_output = gr.Textbox(label = "News Title Generation Output")
272
+
273
+ title_submit.click(generate_title, inputs=[title_input, title_choice, max_new_tokens, length_penalty, no_repeat_ngram_size], outputs=title_output)
274
+ title_examples = gr.Examples(examples = long_text, inputs = [title_input, title_choice, max_new_tokens, length_penalty, no_repeat_ngram_size], outputs=title_output, fn=generate_title)
275
+
276
  with gr.Tab("Text Generation"):
277
  gr.Markdown("Pre-trained TURNA. Enter text to start generating.")
278
  with gr.Column():