Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import streamlit as st | |
| # Prog1: Classifier | |
| # classifier = pipeline("sentiment-analysis") | |
| # res = classifier("I have been waiting for the transformer my whole life") | |
| # print(res) | |
| # Prog2: Text Generator | |
| # generator = pipeline("text-generation", model="distilgpt2") | |
| # res = generator( | |
| # "In this course we will teach you how to", | |
| # max_length=100, | |
| # num_return_sequences=2, | |
| # ) | |
| # st.write(res) | |
| # Prog3: Zero Shot Classifier | |
| # classifier2 = pipeline("zero-shot-classification") | |
| # res = classifier2( | |
| # "This is a course for Python List comprehension", | |
| # candidate_labels = ["education","politics","business"] | |
| # ) | |
| # st.write(res) | |
| # Prog4: Using Automodel and Autotokenizer | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| model_name = "distilbert-base-uncased-finetuned-sst-2-english" | |
| model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| classifier3 = pipeline("sentiment-analysis",model=model,tokenizer=tokenizer) | |
| res = classifier3("Newton has been the biggest physicist in modern times") | |
| st.write(res) | |