Spaces:
Runtime error
Runtime error
Commit
·
a39c327
1
Parent(s):
b35a71a
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,74 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import transformers
|
3 |
-
import torch
|
4 |
|
5 |
-
# Load the model and tokenizer
|
6 |
-
#model = transformers.AutoModelForSequenceClassification.from_pretrained("RICHARDMENSAH/twitter_xlm_roberta_base")
|
7 |
-
# tokenizer = transformers.AutoTokenizer.from_pretrained("RICHARDMENSAH/twitter_xlm_roberta_base")
|
8 |
|
9 |
-
model_name = "RICHARDMENSAH/twitter_xlm_roberta_base"
|
10 |
-
tokenizer_name = "RICHARDMENSAH/twitter_xlm_roberta_base"
|
11 |
|
12 |
-
model = transformers.pipeline("text-classification", model=model_name, tokenizer=tokenizer_name)
|
13 |
|
14 |
-
# Define the function for sentiment analysis
|
15 |
-
@st.cache_resource
|
16 |
-
def predict_sentiment(text):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
# Setting the page configurations
|
30 |
-
st.set_page_config(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
# Add description and title
|
38 |
-
st.write("""
|
39 |
-
# How Positive or Negative is your Text?
|
40 |
-
Enter some text and we'll tell you if it has a positive, negative, or neutral sentiment!
|
41 |
-
""" )
|
42 |
|
43 |
-
# Add image
|
44 |
-
image = st.image("https://i0.wp.com/thedatascientist.com/wp-content/uploads/2018/10/sentiment-analysis.png", width=400)
|
45 |
|
46 |
-
# Get user input
|
47 |
-
text = st.text_input("Enter some text here:")
|
48 |
|
49 |
-
# Define the CSS style for the app
|
50 |
-
st.markdown(
|
51 |
-
"""
|
52 |
-
<style>
|
53 |
-
body {
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
h1 {
|
58 |
-
|
59 |
-
|
60 |
-
</style>
|
61 |
-
""",
|
62 |
-
unsafe_allow_html=True
|
63 |
-
)
|
64 |
|
65 |
|
66 |
-
# Show sentiment output
|
67 |
-
if text:
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# import transformers
|
3 |
+
# import torch
|
4 |
|
5 |
+
# # Load the model and tokenizer
|
6 |
+
# #model = transformers.AutoModelForSequenceClassification.from_pretrained("RICHARDMENSAH/twitter_xlm_roberta_base")
|
7 |
+
# # tokenizer = transformers.AutoTokenizer.from_pretrained("RICHARDMENSAH/twitter_xlm_roberta_base")
|
8 |
|
9 |
+
# model_name = "RICHARDMENSAH/twitter_xlm_roberta_base"
|
10 |
+
# tokenizer_name = "RICHARDMENSAH/twitter_xlm_roberta_base"
|
11 |
|
12 |
+
# model = transformers.pipeline("text-classification", model=model_name, tokenizer=tokenizer_name)
|
13 |
|
14 |
+
# # Define the function for sentiment analysis
|
15 |
+
# @st.cache_resource
|
16 |
+
# def predict_sentiment(text):
|
17 |
+
# result = model(text)
|
18 |
+
# labell = result[0]['label']
|
19 |
+
# if labell == 'label_0':
|
20 |
+
# sentiment = 'Negative'
|
21 |
+
# elif labell == 'label_1':
|
22 |
+
# sentiment = 'Neutral'
|
23 |
+
# elif labell == 'label_2':
|
24 |
+
# sentiment = 'Positive'
|
25 |
+
# else: sentiment = labell
|
26 |
+
# score = result[0]['score']
|
27 |
+
# return sentiment, score
|
28 |
|
29 |
+
# # Setting the page configurations
|
30 |
+
# st.set_page_config(
|
31 |
+
# page_title="Sentiment Analysis App",
|
32 |
+
# page_icon=":smile:",
|
33 |
+
# layout="wide",
|
34 |
+
# initial_sidebar_state="auto",
|
35 |
+
# )
|
36 |
|
37 |
+
# # Add description and title
|
38 |
+
# st.write("""
|
39 |
+
# # How Positive or Negative is your Text?
|
40 |
+
# Enter some text and we'll tell you if it has a positive, negative, or neutral sentiment!
|
41 |
+
# """ )
|
42 |
|
43 |
+
# # Add image
|
44 |
+
# image = st.image("https://i0.wp.com/thedatascientist.com/wp-content/uploads/2018/10/sentiment-analysis.png", width=400)
|
45 |
|
46 |
+
# # Get user input
|
47 |
+
# text = st.text_input("Enter some text here:")
|
48 |
|
49 |
+
# # Define the CSS style for the app
|
50 |
+
# st.markdown(
|
51 |
+
# """
|
52 |
+
# <style>
|
53 |
+
# body {
|
54 |
+
# background-color: #f5f5f5;
|
55 |
+
# }
|
56 |
|
57 |
+
# h1 {
|
58 |
+
# color: #4e79a7;
|
59 |
+
# }
|
60 |
+
# </style>
|
61 |
+
# """,
|
62 |
+
# unsafe_allow_html=True
|
63 |
+
# )
|
64 |
|
65 |
|
66 |
+
# # Show sentiment output
|
67 |
+
# if text:
|
68 |
+
# sentiment, score = predict_sentiment(text)
|
69 |
+
# if sentiment == "Positive":
|
70 |
+
# st.success(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|
71 |
+
# elif sentiment == "Negative":
|
72 |
+
# st.error(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|
73 |
+
# else:
|
74 |
+
# st.warning(f"The sentiment is {sentiment} with a score of {score*100:.2f}%!")
|