Spaces:
Sleeping
Sleeping
fix
Browse files
app.py
CHANGED
@@ -1,9 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
# Load the keyphrase extraction models
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Streamlit app
|
9 |
st.title("Keyphrase Extraction App")
|
@@ -15,15 +20,17 @@ user_input = st.text_area("Text Input", "")
|
|
15 |
# Extract keyphrases
|
16 |
if st.button("Extract Keyphrases"):
|
17 |
if user_input:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
st.write("Extracted Keyphrases from `ml6team/keyphrase-extraction-kbir-inspec`:")
|
22 |
for keyphrase in keyphrases_model1:
|
23 |
st.write(keyphrase['word'])
|
24 |
|
|
|
|
|
|
|
|
|
25 |
st.write("Extracted Keyphrases from `aglazkova/bart_finetuned_keyphrase_extraction`:")
|
26 |
-
|
27 |
-
st.write(keyphrase['word'])
|
28 |
else:
|
29 |
st.write("Please enter some text to extract keyphrases.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline, AutoModelForSeq2SeqLM
|
3 |
|
4 |
# Load the keyphrase extraction models
|
5 |
+
tokenizer1 = AutoTokenizer.from_pretrained("ml6team/keyphrase-extraction-kbir-inspec")
|
6 |
+
model1 = AutoModelForTokenClassification.from_pretrained("ml6team/keyphrase-extraction-kbir-inspec")
|
7 |
+
extractor1 = pipeline("ner", model=model1, tokenizer=tokenizer1)
|
8 |
+
|
9 |
+
tokenizer2 = AutoTokenizer.from_pretrained("aglazkova/bart_finetuned_keyphrase_extraction")
|
10 |
+
model2 = AutoModelForSeq2SeqLM.from_pretrained("aglazkova/bart_finetuned_keyphrase_extraction")
|
11 |
+
extractor2 = pipeline("text2text-generation", model=model2, tokenizer=tokenizer2)
|
12 |
|
13 |
# Streamlit app
|
14 |
st.title("Keyphrase Extraction App")
|
|
|
20 |
# Extract keyphrases
|
21 |
if st.button("Extract Keyphrases"):
|
22 |
if user_input:
|
23 |
+
# Extract keyphrases using the first model
|
24 |
+
keyphrases_model1 = extractor1(user_input)
|
|
|
25 |
st.write("Extracted Keyphrases from `ml6team/keyphrase-extraction-kbir-inspec`:")
|
26 |
for keyphrase in keyphrases_model1:
|
27 |
st.write(keyphrase['word'])
|
28 |
|
29 |
+
# Extract keyphrases using the second model
|
30 |
+
tokenized_text = tokenizer2.prepare_seq2seq_batch([user_input], return_tensors='pt')
|
31 |
+
translation = model2.generate(**tokenized_text)
|
32 |
+
translated_text = tokenizer2.batch_decode(translation, skip_special_tokens=True)[0]
|
33 |
st.write("Extracted Keyphrases from `aglazkova/bart_finetuned_keyphrase_extraction`:")
|
34 |
+
st.write(translated_text)
|
|
|
35 |
else:
|
36 |
st.write("Please enter some text to extract keyphrases.")
|