asd
Browse files
app.py
CHANGED
@@ -1,7 +1,36 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
+
device = "cuda"
|
|
|
5 |
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("NoaiGPT/777")
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("NoaiGPT/777").to(device)
|
8 |
+
|
9 |
+
def generate_title(text):
|
10 |
+
input_ids = tokenizer(f'paraphraser: {text}', return_tensors="pt", padding="longest", truncation=True, max_length=64).input_ids.to(device)
|
11 |
+
outputs = model.generate(
|
12 |
+
input_ids,
|
13 |
+
num_beams=4,
|
14 |
+
num_beam_groups=4,
|
15 |
+
num_return_sequences=4,
|
16 |
+
repetition_penalty=10.0,
|
17 |
+
diversity_penalty=3.0,
|
18 |
+
no_repeat_ngram_size=2,
|
19 |
+
temperature=0.8,
|
20 |
+
max_length=64
|
21 |
+
)
|
22 |
+
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
23 |
+
|
24 |
+
def gradio_generate_title(text):
|
25 |
+
titles = generate_title(text)
|
26 |
+
return "\n\n".join(titles)
|
27 |
+
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=gradio_generate_title,
|
30 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
31 |
+
outputs=gr.Textbox(lines=10, label="Generated Titles"),
|
32 |
+
title="Title Generator",
|
33 |
+
description="Generate multiple paraphrased titles from input text using NoaiGPT/777 model."
|
34 |
+
)
|
35 |
+
|
36 |
+
iface.launch()
|