File size: 867 Bytes
567db95
eb311d6
068cd45
567db95
068cd45
 
 
 
eb311d6
 
068cd45
 
 
 
eb311d6
 
068cd45
eb311d6
 
 
 
068cd45
 
eb311d6
 
068cd45
eb311d6
068cd45
 
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
import streamlit as st
from transformers import pipeline
from huggingface_hub import HfApi, ModelFilter

# Set up Hugging Face Hub API client
api = HfApi()

# Display title
st.title("Text Sentiment Analyzer")

# Retrieve all text classification models
models = api.list_models(filter=ModelFilter(task="text-classification"))[:10]
model_ids = [model.modelId for model in models]

# Create submission form
form = st.form("sentiment-form")
select_model = form.selectbox("Select a pretrained model", model_ids)
input = form.text_area('Enter your text here.')
submit = form.form_submit_button("Submit")

if submit:
    # Create pipeline to user's selected pre-trained model
    classifier = pipeline(task="sentiment-analysis", model=select_model)
    
    # Extract prediction from the results
    pred = classifier(input)
    
    # Display prediction
    st.write(pred)