Spaces:
Runtime error
Runtime error
Commit
•
8df1c7e
1
Parent(s):
1c716b5
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
# import sentencepiece
|
2 |
|
3 |
|
4 |
-
import streamlit as st
|
5 |
-
from transformers import pipeline
|
6 |
|
7 |
-
sentiment_analysis = pipeline("sentiment-analysis")
|
8 |
-
translation = pipeline("translation_en_to_ar", model="anibahug/marian-finetuned-kde4-en-to-ar")
|
9 |
|
10 |
-
text = st.text_input("Enter some text")
|
11 |
|
12 |
-
if text:
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
if text:
|
17 |
-
|
18 |
-
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
|
36 |
-
#
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
#
|
41 |
-
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
|
|
1 |
# import sentencepiece
|
2 |
|
3 |
|
4 |
+
# import streamlit as st
|
5 |
+
# from transformers import pipeline
|
6 |
|
7 |
+
# sentiment_analysis = pipeline("sentiment-analysis")
|
8 |
+
# translation = pipeline("translation_en_to_ar", model="anibahug/marian-finetuned-kde4-en-to-ar")
|
9 |
|
10 |
+
# text = st.text_input("Enter some text")
|
11 |
|
12 |
+
# if text:
|
13 |
+
# result = sentiment_analysis(text)
|
14 |
+
# st.json(result)
|
15 |
|
16 |
+
# if text:
|
17 |
+
# result = translation(text)[0]
|
18 |
+
# st.write(f"Translated text: {result['translation_text']}")
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
+
import streamlit as st
|
25 |
+
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
26 |
|
27 |
+
# Load sentiment analysis model from Hugging Face
|
28 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
29 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
31 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
32 |
|
33 |
+
# Streamlit UI
|
34 |
+
st.title("Sentiment Analysis App")
|
35 |
|
36 |
+
# User input
|
37 |
+
user_input = st.text_input("Enter a sentence:")
|
38 |
|
39 |
+
if user_input:
|
40 |
+
# Perform sentiment analysis
|
41 |
+
results = sentiment_analyzer(user_input)
|
42 |
|
43 |
+
# Display sentiment and confidence
|
44 |
+
sentiment = results[0]['label']
|
45 |
+
confidence = results[0]['score']
|
46 |
|
47 |
+
st.write(f"Sentiment: {sentiment}")
|
48 |
+
st.write(f"Confidence: {confidence:.2f}")
|