Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import torch
|
|
| 5 |
|
| 6 |
model_name = "Timur1984/t5-base-title-generation" # тут конечно всем надо поставить свой акк и имя модели
|
| 7 |
|
| 8 |
-
|
| 9 |
print("Loading model...")
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 11 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
@@ -28,61 +27,20 @@ def generate_titles(text, num_titles, temperature):
|
|
| 28 |
)
|
| 29 |
|
| 30 |
decoded = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
| 31 |
-
|
| 32 |
titles = [nltk.sent_tokenize(t.strip())[0] for t in decoded]
|
| 33 |
|
| 34 |
-
return "\n".join(
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 38 |
-
|
| 39 |
-
gr.Markdown(
|
| 40 |
-
"""
|
| 41 |
-
# 📰 AI Article Title Generator
|
| 42 |
-
|
| 43 |
-
Вставьте текст статьи — модель сгенерирует несколько вариантов заголовков.
|
| 44 |
-
"""
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
with gr.Row():
|
| 48 |
-
|
| 49 |
-
with gr.Column(scale=3):
|
| 50 |
|
| 51 |
-
text = gr.Textbox(
|
| 52 |
-
label="Article text",
|
| 53 |
-
lines=15,
|
| 54 |
-
placeholder="Paste article text here..."
|
| 55 |
-
)
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
temperature = gr.Slider(
|
| 70 |
-
0.1,
|
| 71 |
-
1.5,
|
| 72 |
-
value=0.7,
|
| 73 |
-
step=0.05,
|
| 74 |
-
label="Temperature"
|
| 75 |
-
)
|
| 76 |
-
|
| 77 |
-
output = gr.Textbox(
|
| 78 |
-
label="Generated titles",
|
| 79 |
-
lines=10
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
generate_btn.click(
|
| 83 |
-
fn=generate_titles,
|
| 84 |
-
inputs=[text, num_titles, temperature],
|
| 85 |
-
outputs=output
|
| 86 |
-
)
|
| 87 |
|
| 88 |
-
|
|
|
|
| 5 |
|
| 6 |
model_name = "Timur1984/t5-base-title-generation" # тут конечно всем надо поставить свой акк и имя модели
|
| 7 |
|
|
|
|
| 8 |
print("Loading model...")
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
decoded = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
|
|
|
| 30 |
titles = [nltk.sent_tokenize(t.strip())[0] for t in decoded]
|
| 31 |
|
| 32 |
+
return "\n".join(titles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
interface = gr.Interface(
|
| 36 |
+
fn=generate_titles,
|
| 37 |
+
inputs=[
|
| 38 |
+
gr.Textbox(lines=15, label="Article text"),
|
| 39 |
+
gr.Slider(1,10,value=5,step=1,label="Number of titles"),
|
| 40 |
+
gr.Slider(0.1,1.5,value=0.7,step=0.05,label="Temperature")
|
| 41 |
+
],
|
| 42 |
+
outputs="text",
|
| 43 |
+
title="Article Title Generator"
|
| 44 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
interface.launch()
|