Spaces:
Runtime error
Runtime error
demo for titles generation
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
import nltk
|
5 |
+
nltk.download('punkt')
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("fabiochiu/t5-small-medium-title-generation")
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("fabiochiu/t5-small-medium-title-generation")
|
9 |
+
|
10 |
+
text = st.text_area('Enter an abstract to summerize, i.e. generate a title!')
|
11 |
+
|
12 |
+
|
13 |
+
if text:
|
14 |
+
inputs = ["summarize: " + text]
|
15 |
+
inputs = tokenizer(inputs, max_length=max_input_length, truncation=True, return_tensors="pt")
|
16 |
+
output = model.generate(**inputs, num_beams=8, do_sample=True, min_length=10, max_length=64)
|
17 |
+
decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
|
18 |
+
predicted_title = nltk.sent_tokenize(decoded_output.strip())[0]
|
19 |
+
|
20 |
+
html_string = f"<h3>{predicted_title}</h3>"
|
21 |
+
|
22 |
+
st.markdown(html_string, unsafe_allow_html=True)
|