Spaces:
Runtime error
Runtime error
Commit
•
446a37b
1
Parent(s):
7c7004e
Upload 2 files
Browse files- requirements.txt +3 -0
- streamlit_app.py +105 -0
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
torch
|
streamlit_app.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load models
|
5 |
+
|
6 |
+
# Distilled Sentiment Classifier
|
7 |
+
# Link: https://huggingface.co/lxyuan/distilbert-base-multilingual-cased-sentiments-student
|
8 |
+
distilled_sentiment_classifier = pipeline(
|
9 |
+
model="lxyuan/distilbert-base-multilingual-cased-sentiments-student",
|
10 |
+
return_all_scores=True
|
11 |
+
)
|
12 |
+
|
13 |
+
# Emotion Classifier
|
14 |
+
# Link: https://huggingface.co/SamLowe/roberta-base-go_emotions
|
15 |
+
emotion_text_classifier = pipeline("text-classification", model="SamLowe/roberta-base-go_emotions")
|
16 |
+
|
17 |
+
# Named Entity Recognition
|
18 |
+
# Link: https://huggingface.co/mdarhri00/named-entity-recognition
|
19 |
+
named_entity_classifier = pipeline("token-classification", model="mdarhri00/named-entity-recognition")
|
20 |
+
|
21 |
+
# Toxicity Classifier
|
22 |
+
# Link: https://huggingface.co/s-nlp/roberta_toxicity_classifier
|
23 |
+
toxicity_classifier = pipeline("text-classification", model="s-nlp/roberta_toxicity_classifier")
|
24 |
+
|
25 |
+
# Streamlit app
|
26 |
+
def main():
|
27 |
+
st.title("HuggingFace Model Demo App")
|
28 |
+
|
29 |
+
# User input for text
|
30 |
+
user_text = st.text_area("Enter some text:")
|
31 |
+
|
32 |
+
if user_text:
|
33 |
+
# Available Models
|
34 |
+
# Sentiment Analysis
|
35 |
+
sentiment_checkbox = st.checkbox("Sentiment Analysis")
|
36 |
+
|
37 |
+
# Emotion Analysis
|
38 |
+
emotion_checkbox = st.checkbox("Emotion Analysis")
|
39 |
+
|
40 |
+
# Named Entity Recognition
|
41 |
+
ner_checkbox = st.checkbox("Named Entity Recognition")
|
42 |
+
|
43 |
+
# Toxicity Analysis
|
44 |
+
toxicity_checkbox = st.checkbox("Toxicity Analysis")
|
45 |
+
|
46 |
+
# Run custom and display outputs
|
47 |
+
st.header("Function Outputs:")
|
48 |
+
|
49 |
+
if sentiment_checkbox:
|
50 |
+
st.subheader("Sentiment Analysis:")
|
51 |
+
|
52 |
+
# Parse JSON data
|
53 |
+
data = distilled_sentiment_classifier(user_text)
|
54 |
+
|
55 |
+
# Extract and display label and score values
|
56 |
+
for labels_and_scores in data:
|
57 |
+
for entry in labels_and_scores:
|
58 |
+
label = entry["label"]
|
59 |
+
score = entry["score"]
|
60 |
+
st.write(f"Label: {label}, Score: {score}")
|
61 |
+
|
62 |
+
|
63 |
+
if emotion_checkbox:
|
64 |
+
st.subheader("Emotion Analysis:")
|
65 |
+
|
66 |
+
# Parse JSON data
|
67 |
+
data = emotion_text_classifier(user_text)
|
68 |
+
|
69 |
+
# Extract and display label and score values
|
70 |
+
for labels_and_scores in data:
|
71 |
+
for entry in labels_and_scores:
|
72 |
+
label = entry["label"]
|
73 |
+
score = entry["score"]
|
74 |
+
st.write(f"Label: {label}, Score: {score}")
|
75 |
+
|
76 |
+
if ner_checkbox:
|
77 |
+
st.subheader("Named Entity Recognition:")
|
78 |
+
|
79 |
+
# Parse JSON data
|
80 |
+
data = named_entity_classifier(user_text)
|
81 |
+
|
82 |
+
# Extract and display data
|
83 |
+
for entry in data:
|
84 |
+
entity_group = entry["entity_group"]
|
85 |
+
score = entry["score"]
|
86 |
+
word = entry["word"]
|
87 |
+
start = entry["start"]
|
88 |
+
end = entry["end"]
|
89 |
+
st.write(f"Word: {word}, Entity Group: {entity_group}, Score: {score}, Start: {start}, End: {end}")
|
90 |
+
|
91 |
+
if toxicity_checkbox:
|
92 |
+
st.subheader("Toxicity Analysis:")
|
93 |
+
|
94 |
+
# Parse JSON data
|
95 |
+
data = toxicity_classifier(user_text)
|
96 |
+
|
97 |
+
# Extract and display label and score values
|
98 |
+
for labels_and_scores in data:
|
99 |
+
for entry in labels_and_scores:
|
100 |
+
label = entry["label"]
|
101 |
+
score = entry["score"]
|
102 |
+
st.write(f"Label: {label}, Score: {score}")
|
103 |
+
|
104 |
+
if __name__ == "__main__":
|
105 |
+
main()
|