Spaces:
Sleeping
Sleeping
File size: 2,157 Bytes
2c87b44 9877e49 2c87b44 08a9420 d2e13e2 08a9420 d2e13e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
from transformers import pipeline
def build_pipeline(text : str, model : str):
st.text(f"Using model {model}")
classifier = pipeline(task=text, model=model)
return classifier
st.header('Pipeline Examples', divider='rainbow')
st.subheader('Enter some text to demonstrate different pipeline/model analysis', divider='grey')
option = st.selectbox('Select model task:', ('sentiment-analysis', 'summarization', 'text-generation', 'translation', 'zero-shot-classification'))
text = st.text_area('Text to analyse:', "Star Trek Enterprise follows the adventures of the crew of the first starship Enterprise, designation NX-01. They are the first deep space explorers in Starfleet, using the first warp five capable vessel. The Vulcans have withheld advanced technology from humanity since their first contact, concerned that humans were not ready for it. This has delayed human space exploration and caused resentment in Starfleet test pilot Jonathan Archer, whose father developed the Warp 5 engine but did not live to see it used.", height=200)
st.write(f'{len(text)} characters')
st.button('Analyse', type='primary')
st.subheader(f'{option}', divider='grey')
output = {}
with st.spinner("Analysing..."):
if option == 'sentiment-analysis':
classifier = build_pipeline(text=option, model='distilbert-base-uncased-finetuned-sst-2-english')
output = classifier(text)
elif option == 'summarization':
classifier = build_pipeline(text=option, model='facebook/bart-large-cnn')
output = classifier(text, min_length=5, max_length=50, do_sample=False)
elif option == 'text-generation':
classifier = build_pipeline(text=option, model='distilgpt2')
output = classifier(text)
elif option == 'zero-shot-classification':
classifier = build_pipeline(text=option, model='distilgpt2')
output = classifier(text, candidate_labels=["space", "dicovery", "humans"])
elif option == 'translation':
classifier = build_pipeline(text="translation", model='Helsinki-NLP/opus-mt-en-es')
output = classifier(text)
st.success("Complete")
st.json(output)
|