Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
auth_token = os.environ.get("CLARIN_KNEXT")
|
| 7 |
+
|
| 8 |
+
model_name = "clarin-knext/keywords-plt5-small-shuffle"
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=auth_token)
|
| 10 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name, use_auth_token=auth_token)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
default_generate_kwargs = {
|
| 14 |
+
"max_length": 32,
|
| 15 |
+
"num_beams": 4,
|
| 16 |
+
"length_penalty": 1.5,
|
| 17 |
+
"no_repeat_ngram_size": 3,
|
| 18 |
+
"early_stopping": True,
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
keywords_pipe = pipeline(model=model, tokenizer=tokenizer, **default_generate_kwargs)
|
| 22 |
+
|
| 23 |
+
examples = [
|
| 24 |
+
["The Moon's orbit around Earth has"],
|
| 25 |
+
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
def generate(text):
|
| 29 |
+
return keywords_pipe("keywords: " + text)
|
| 30 |
+
|
| 31 |
+
demo = gr.Interface(
|
| 32 |
+
fn=generate,
|
| 33 |
+
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
| 34 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 35 |
+
examples=examples
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|