Spaces:
Runtime error
Runtime error
theresatvan
commited on
Commit
•
068cd45
1
Parent(s):
e870b86
Add model selection feature
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
|
|
|
|
|
|
|
|
4 |
st.title("Text Sentiment Analyzer")
|
5 |
|
|
|
|
|
|
|
|
|
6 |
# Create submission form
|
7 |
form = st.form("sentiment-form")
|
|
|
8 |
input = form.text_area('Enter your text here.')
|
9 |
submit = form.form_submit_button("Submit")
|
10 |
|
11 |
if submit:
|
12 |
-
#
|
13 |
-
classifier = pipeline(task="sentiment-analysis")
|
14 |
|
15 |
# Extract prediction from the results
|
16 |
-
pred = classifier(input)
|
17 |
-
label= pred['label']
|
18 |
-
score = pred['score']
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
st.success("{} sentiment (score: {})".format(label, score))
|
23 |
-
|
24 |
-
else:
|
25 |
-
# Red output text box
|
26 |
-
st.error("{} sentiment (score: {})".format(label, score))
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
from huggingface_hub import HfApi, ModelFilter
|
4 |
|
5 |
+
# Set up Hugging Face Hub API client
|
6 |
+
api = HfApi()
|
7 |
+
|
8 |
+
# Display title
|
9 |
st.title("Text Sentiment Analyzer")
|
10 |
|
11 |
+
# Retrieve all text classification models
|
12 |
+
models = api.list_models(filter=ModelFilter(task="text-classification"))[:10]
|
13 |
+
model_ids = [model.modelId for model in models]
|
14 |
+
|
15 |
# Create submission form
|
16 |
form = st.form("sentiment-form")
|
17 |
+
select_model = form.selectbox("Select a pretrained model", model_ids)
|
18 |
input = form.text_area('Enter your text here.')
|
19 |
submit = form.form_submit_button("Submit")
|
20 |
|
21 |
if submit:
|
22 |
+
# Create pipeline to user's selected pre-trained model
|
23 |
+
classifier = pipeline(task="sentiment-analysis", model=select_model)
|
24 |
|
25 |
# Extract prediction from the results
|
26 |
+
pred = classifier(input)
|
|
|
|
|
27 |
|
28 |
+
# Display prediction
|
29 |
+
st.write(pred)
|
|
|
|
|
|
|
|
|
|