Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
|
4 |
-
|
5 |
-
nlp = spacy.load("en_core_web_sm")
|
6 |
|
7 |
-
|
8 |
-
def main():
|
9 |
-
st.title("Named Entity Recognition (NER) Demo")
|
10 |
|
11 |
-
# User input
|
12 |
-
text_input = st.text_area("Enter text:", "John Doe is the CEO of ABC Corp, and it is located in New York.")
|
13 |
|
14 |
-
|
15 |
-
if st.button("Extract Entities"):
|
16 |
-
doc = nlp(text_input)
|
17 |
|
18 |
-
|
19 |
-
entities = [(ent.text, ent.label_) for ent in doc.ents]
|
20 |
-
st.write("Named Entities:")
|
21 |
-
for entity, label in entities:
|
22 |
-
st.write(f"- {entity} ({label})")
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
model_path = "citizenlab/twitter-xlm-roberta-base-sentiment-finetunned"
|
|
|
5 |
|
6 |
+
st.set_page_config(page_title="Sentiment Analysis App")
|
|
|
|
|
7 |
|
|
|
|
|
8 |
|
9 |
+
sentiment_classifier = pipeline("text-classification", model=model_path, tokenizer=model_path)
|
|
|
|
|
10 |
|
11 |
+
st.title("Sentiment Analysis App")
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
user_input = st.text_area("Enter a message:")
|
14 |
+
|
15 |
+
if st.button("Analyze Sentiment"):
|
16 |
+
if user_input:
|
17 |
+
# Perform sentiment analysis
|
18 |
+
results = sentiment_classifier(user_input)
|
19 |
+
sentiment_label = results[0]["label"]
|
20 |
+
sentiment_score = results[0]["score"]
|
21 |
+
|
22 |
+
st.write(f"Sentiment: {sentiment_label}")
|
23 |
+
st.write(f"Confidence Score: {sentiment_score:.2f}")
|
24 |
+
|
25 |
+
# Run the Streamlit app
|
26 |
+
if _name_ == "_main_":
|
27 |
+
st.write("Enter a message and click 'Analyze Sentiment' to classify its sentiment.")
|