Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import torch
|
|
| 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,20 +28,61 @@ def generate_titles(text, num_titles, temperature):
|
|
| 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 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
| 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 |
)
|
| 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([f"• {t}" for t in titles])
|
| 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 |
+
generate_btn = gr.Button("Generate titles 🚀")
|
| 58 |
+
|
| 59 |
+
with gr.Column(scale=1):
|
| 60 |
+
|
| 61 |
+
num_titles = gr.Slider(
|
| 62 |
+
1,
|
| 63 |
+
10,
|
| 64 |
+
value=5,
|
| 65 |
+
step=1,
|
| 66 |
+
label="Number of titles"
|
| 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 |
+
demo.launch()
|