nurindahpratiwi commited on
Commit
a3eeec7
1 Parent(s): 552acce

change some log

Browse files
Files changed (2) hide show
  1. app.py +7 -14
  2. app_.py +17 -0
app.py CHANGED
@@ -1,27 +1,20 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # title
5
  st.title("Sentiment Analysis App")
6
  st.markdown("You can input 8 different language: arabic, english, french, german, hindi, italian, portuguese, spanish")
7
 
8
- # text input
9
  text = st.text_input("Enter text here", "I love you")
10
 
11
  # Model initiate
12
- model = "cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual"
13
-
14
- # Sentiment analysis function
15
- def analyze_sentiment(text, model):
16
- if model == "cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual":
17
- classifier = pipeline("sentiment-analysis", model=model)
18
- result = classifier(text)[0]
19
- sentiment = result['label']
20
- score = result['score']
21
- return sentiment, score
22
 
23
  if st.button("Analyze"):
24
- sentiment, score = analyze_sentiment(text, model)
 
 
25
  st.write(f"Sentiment: {sentiment}")
26
  if score is not None:
27
- st.write(f"Score: {score}")
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Buat title pada web apps
5
  st.title("Sentiment Analysis App")
6
  st.markdown("You can input 8 different language: arabic, english, french, german, hindi, italian, portuguese, spanish")
7
 
8
+ # Buat text input dari user
9
  text = st.text_input("Enter text here", "I love you")
10
 
11
  # Model initiate
12
+ pipeline = pipeline(task='text-classification', model='cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual')
 
 
 
 
 
 
 
 
 
13
 
14
  if st.button("Analyze"):
15
+ result = pipeline(text)
16
+ sentiment = result['label']
17
+ score = result['score']
18
  st.write(f"Sentiment: {sentiment}")
19
  if score is not None:
20
+ st.write(f"Score: {score}")
app_.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Sentiment analysis function
4
+ def analyze_sentiment(text, model):
5
+ if model == "cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual":
6
+ classifier = pipeline("sentiment-analysis", model=model)
7
+ result = classifier(text)[0]
8
+ sentiment = result['label']
9
+ score = result['score']
10
+ return sentiment, score
11
+
12
+ # Buat button analyze yang melaukan perintah sebagai berikut
13
+ if st.button("Analyze"):
14
+ sentiment, score = analyze_sentiment(text, model)
15
+ st.write(f"Sentiment: {sentiment}")
16
+ if score is not None:
17
+ st.write(f"Score: {score}")