Dilwolf commited on
Commit
5d525d9
ยท
verified ยท
1 Parent(s): 081ee4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -14,30 +14,30 @@ tokenizer, model = get_model()
14
 
15
  # Define the "How to Use" message
16
  how_to_use = """
17
- **How to Use**
18
- 1. Enter text in the text area
19
- 2. Click the 'Analyze' button to get the predicted sentiment of the input text
20
  """
21
 
22
  # Functions
23
  def main():
24
- st.title("KakaoTalk App Review Sentiment Analysis using BERT")
25
- st.subheader("Dilshod's Portfolio Project")
26
 
27
  # Add the cover image
28
  st.image("img/kakaotalk.png")
29
 
30
- menu = ["Home", "About"]
31
  choice = st.sidebar.selectbox("Menu", menu)
32
 
33
  # Add the "How to Use" message to the sidebar
34
  st.sidebar.markdown(how_to_use)
35
 
36
- if choice == "Home":
37
- st.subheader("Home")
38
 
39
  with st.form(key="nlpForm"):
40
- raw_text = st.text_area("Enter Text Here")
41
  submit_button = st.form_submit_button(label="Analyze")
42
 
43
  # Layout
@@ -46,7 +46,7 @@ def main():
46
  # Display balloons
47
  st.balloons()
48
  with col1:
49
- st.info("Results")
50
  # Tokenize the input text
51
  inputs = tokenizer([raw_text], padding=True, truncation=True, max_length=512, return_tensors='pt')
52
 
@@ -58,32 +58,32 @@ def main():
58
  scores = outputs.logits.softmax(dim=1).detach().numpy()[0]
59
 
60
  # Mapping of prediction to sentiment labels
61
- sentiment_dict = {0: 'Negative', 1: 'Positive'}
62
  sentiment_label = sentiment_dict[predicted_class]
63
  confidence_level = scores[predicted_class]
64
 
65
  # Display sentiment
66
- st.write(f"Sentiment: {sentiment_label}, Confidence Level: {confidence_level:.2f}")
67
 
68
  # Emoji and sentiment image
69
  if predicted_class == 1:
70
- st.markdown("Sentiment: Positive :smiley:")
71
  st.image("img/positive_emoji.jpg")
72
  else:
73
- st.markdown("Sentiment: Negative :angry:")
74
  st.image("img/negative_emoji.jpg")
75
 
76
  # Create the results DataFrame
77
  results_df = pd.DataFrame({
78
- 'Sentiment Class': ['Negative', 'Positive'],
79
  'Score': scores
80
  })
81
 
82
  # Create the Altair chart
83
  chart = alt.Chart(results_df).mark_bar(width=50).encode(
84
- x="Sentiment Class",
85
- y="Score",
86
- color="Sentiment Class"
87
  )
88
 
89
  # Display the chart
@@ -92,8 +92,8 @@ def main():
92
  st.write(results_df)
93
 
94
  else:
95
- st.subheader("About")
96
- st.write("This is a sentiment analysis NLP app developed by Dilshod for analyzing reviews for KakakTalk mobile app on Google Play Store. It uses a fine-tuned model to predict the sentiment of the input text. The app is part of a portfolio project to showcase my nlp skills and collaboration among developers.")
97
 
98
  if __name__ == "__main__":
99
  main()
 
14
 
15
  # Define the "How to Use" message
16
  how_to_use = """
17
+ **์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•**
18
+ 1. ํ…์ŠคํŠธ ์˜์—ญ์— ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
19
+ 2. ํ•œ๊ตญ์–ด ์ž…๋ ฅ ํ…์ŠคํŠธ์˜ ์˜ˆ์ธก ๊ฐ์ •์„ ์–ป์œผ๋ ค๋ฉด '๋ถ„์„' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”.
20
  """
21
 
22
  # Functions
23
  def main():
24
+ st.title("BERT๋ฅผ ํ™œ์šฉํ•œ ์นด์นด์˜คํ†ก ์•ฑ ๋ฆฌ๋ทฐ ๊ฐ์„ฑ ๋ถ„์„")
25
+ st.subheader("Dilshod์˜ ํฌํŠธํด๋ฆฌ์˜ค ํ”„๋กœ์ ํŠธ")
26
 
27
  # Add the cover image
28
  st.image("img/kakaotalk.png")
29
 
30
+ menu = ["ํ™ˆ", "์†Œ๊ฐœ"]
31
  choice = st.sidebar.selectbox("Menu", menu)
32
 
33
  # Add the "How to Use" message to the sidebar
34
  st.sidebar.markdown(how_to_use)
35
 
36
+ if choice == "ํ™ˆ":
37
+ st.subheader("ํ™ˆ")
38
 
39
  with st.form(key="nlpForm"):
40
+ raw_text = st.text_area("์—ฌ๊ธฐ์— ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”!")
41
  submit_button = st.form_submit_button(label="Analyze")
42
 
43
  # Layout
 
46
  # Display balloons
47
  st.balloons()
48
  with col1:
49
+ st.info("๊ฒฐ๊ณผ")
50
  # Tokenize the input text
51
  inputs = tokenizer([raw_text], padding=True, truncation=True, max_length=512, return_tensors='pt')
52
 
 
58
  scores = outputs.logits.softmax(dim=1).detach().numpy()[0]
59
 
60
  # Mapping of prediction to sentiment labels
61
+ sentiment_dict = {0: '๋ถ€์ •์ ์ธ', 1: '๊ธ์ •์ ์ธ'}
62
  sentiment_label = sentiment_dict[predicted_class]
63
  confidence_level = scores[predicted_class]
64
 
65
  # Display sentiment
66
+ st.write(f"๊ฐ์ •: {sentiment_label}, ์‹ ๋ขฐ ์ ์ˆ˜: {confidence_level:.2f}")
67
 
68
  # Emoji and sentiment image
69
  if predicted_class == 1:
70
+ st.markdown("๊ฐ์ • ํด๋ž˜์Šค: ๊ธ์ •์ ์ธ :smiley:")
71
  st.image("img/positive_emoji.jpg")
72
  else:
73
+ st.markdown("๊ฐ์ • ํด๋ž˜์Šค: ๋ถ€์ •์ ์ธ :angry:")
74
  st.image("img/negative_emoji.jpg")
75
 
76
  # Create the results DataFrame
77
  results_df = pd.DataFrame({
78
+ '๊ฐ์ • ํด๋ž˜์Šค': ['๋ถ€์ •์ ์ธ', '๊ธ์ •์ ์ธ'],
79
  'Score': scores
80
  })
81
 
82
  # Create the Altair chart
83
  chart = alt.Chart(results_df).mark_bar(width=50).encode(
84
+ x="๊ฐ์ • ํด๋ž˜์Šค",
85
+ y="์‹ ๋ขฐ ์ ์ˆ˜",
86
+ color="๊ฐ์ • ํด๋ž˜์Šค"
87
  )
88
 
89
  # Display the chart
 
92
  st.write(results_df)
93
 
94
  else:
95
+ st.subheader("์†Œ๊ฐœ")
96
+ st.write("์ด๊ฒƒ์€ ๊ตฌ๊ธ€ ํ”Œ๋ ˆ์ด ์Šคํ† ์–ด์—์„œ ๊ฐ€ํ†ก ๋ชจ๋ฐ”์ผ ์•ฑ ๋ฆฌ๋ทฐ๋ฅผ ๋ถ„์„ํ•˜๊ธฐ ์œ„ํ•ด Dilshod๊ฐ€ ๊ฐœ๋ฐœํ•œ ๊ฐ์„ฑ ๋ถ„์„ NLP ์•ฑ์ž…๋‹ˆ๋‹ค. ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ์˜ ๊ฐ์ •์„ ์˜ˆ์ธกํ•˜๊ธฐ ์œ„ํ•ด ์ •๋ฐ€ํ•˜๊ฒŒ ์กฐ์ •๋œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ์•ฑ์€ ์ €์˜ NLP ๊ธฐ์ˆ ๊ณผ ๊ฐœ๋ฐœ์ž ๊ฐ„์˜ ํ˜‘์—…์„ ๋ณด์—ฌ์ฃผ๋Š” ํฌํŠธํด๋ฆฌ์˜ค ํ”„๋กœ์ ํŠธ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค.")
97
 
98
  if __name__ == "__main__":
99
  main()