Spaces:
Runtime error
Runtime error
Commit
·
93f6c86
1
Parent(s):
94991cc
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
| 3 |
-
|
| 4 |
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-small-finetuned-quora-for-paraphrasing")
|
| 6 |
model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/t5-small-finetuned-quora-for-paraphrasing")
|
|
@@ -14,25 +13,23 @@ right_column.selectbox('Question Generator', ['T5', 'GPT Neo-X'])
|
|
| 14 |
|
| 15 |
input = st.text_area("Input Text")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
if st.button('Generate'):
|
| 19 |
st.write(input)
|
|
|
|
| 20 |
st.success("We have generated 105 Questions for you")
|
| 21 |
st.snow()
|
| 22 |
##else:
|
| 23 |
##nothing here
|
| 24 |
-
|
| 25 |
-
def paraphrase(text, max_length=128):
|
| 26 |
-
|
| 27 |
-
input_ids = tokenizer.encode(text, return_tensors="pt", add_special_tokens=True)
|
| 28 |
-
|
| 29 |
-
generated_ids = model.generate(input_ids=input_ids, num_return_sequences=5, num_beams=5, max_length=max_length, no_repeat_ngram_size=2, repetition_penalty=3.5, length_penalty=1.0, early_stopping=True)
|
| 30 |
-
|
| 31 |
-
preds = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in generated_ids]
|
| 32 |
-
|
| 33 |
-
return preds
|
| 34 |
-
|
| 35 |
-
preds = paraphrase("paraphrase: What is the best framework for dealing with a huge text dataset?")
|
| 36 |
-
|
| 37 |
-
for pred in preds:
|
| 38 |
-
st.write(pred)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-small-finetuned-quora-for-paraphrasing")
|
| 5 |
model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/t5-small-finetuned-quora-for-paraphrasing")
|
|
|
|
| 13 |
|
| 14 |
input = st.text_area("Input Text")
|
| 15 |
|
| 16 |
+
def summarize(text):
|
| 17 |
+
# Refer to https://huggingface.co/docs/transformers/v4.18.0/en/main_classes/pipelines#transformers.SummarizationPipeline
|
| 18 |
+
# for further information about configuration.
|
| 19 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 20 |
+
# Refer to https://huggingface.co/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig
|
| 21 |
+
# for further configuration of of the
|
| 22 |
+
output: list = summarizer(
|
| 23 |
+
text,
|
| 24 |
+
max_length=130,
|
| 25 |
+
min_length=30,
|
| 26 |
+
do_sample=False)
|
| 27 |
+
return output
|
| 28 |
|
| 29 |
if st.button('Generate'):
|
| 30 |
st.write(input)
|
| 31 |
+
st.write(summarize(input))
|
| 32 |
st.success("We have generated 105 Questions for you")
|
| 33 |
st.snow()
|
| 34 |
##else:
|
| 35 |
##nothing here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|