Spaces:
Runtime error
Runtime error
init app
Browse files- app.py +51 -0
- images/favicon_vl.png +0 -0
- images/sVL-NLP-short.png +0 -0
- images/vl-logo-nlp-blue.png +0 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
2 |
+
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
tokenizer= T5Tokenizer.from_pretrained("Voicelab/vlt5-base-keywords")
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained("Voicelab/vlt5-base-keywords")
|
7 |
+
|
8 |
+
img_full = Image.open("images/vl-logo-nlp-blue.png")
|
9 |
+
img_short = Image.open("images/vl-logo-nlp-short.png")
|
10 |
+
img_favicon = Image.open("images/favicon_vl.png")
|
11 |
+
max_length: int = 1000
|
12 |
+
cache_size: int = 100
|
13 |
+
|
14 |
+
st.set_page_config(
|
15 |
+
page_title='DEMO - keywords generation',
|
16 |
+
page_icon=img_favicon,
|
17 |
+
initial_sidebar_state="expanded",
|
18 |
+
)
|
19 |
+
|
20 |
+
def get_predictions(text):
|
21 |
+
input_ids = tokenizer(
|
22 |
+
text, return_tensors="pt", truncation=True
|
23 |
+
).input_ids
|
24 |
+
output = model.generate(input_ids, no_repeat_ngram_size=3, num_beams=4)
|
25 |
+
predicted_kw = tokenizer.decode(output[0], skip_special_tokens=True)
|
26 |
+
return predicted_kw
|
27 |
+
|
28 |
+
def trim_length():
|
29 |
+
if len(st.session_state["input"]) > max_length:
|
30 |
+
st.session_state["input"] = st.session_state["input"][:max_length]
|
31 |
+
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
st.sidebar.image(img_short)
|
35 |
+
st.image(img_full)
|
36 |
+
st.title('VLT5 - keywords generation')
|
37 |
+
|
38 |
+
generated_keywords = ""
|
39 |
+
user_input = st.text_area(
|
40 |
+
label=f"Input text (max {max_length} characters)",
|
41 |
+
value="",
|
42 |
+
height=300,
|
43 |
+
on_change=trim_length,
|
44 |
+
key="input",
|
45 |
+
)
|
46 |
+
|
47 |
+
result = st.button("Generate keywords")
|
48 |
+
if result:
|
49 |
+
generated_keywords = get_predictions(text=user_input)
|
50 |
+
st.text_area("Generated keywords", generated_keywords)
|
51 |
+
|
images/favicon_vl.png
ADDED
images/sVL-NLP-short.png
ADDED
images/vl-logo-nlp-blue.png
ADDED
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
transformers[sentencepiece]
|
5 |
+
PIL
|