Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,30 +14,30 @@ tokenizer, model = get_model()
|
|
| 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("
|
| 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,7 +46,7 @@ def main():
|
|
| 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,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: '
|
| 62 |
sentiment_label = sentiment_dict[predicted_class]
|
| 63 |
confidence_level = scores[predicted_class]
|
| 64 |
|
| 65 |
# Display sentiment
|
| 66 |
-
st.write(f"
|
| 67 |
|
| 68 |
# Emoji and sentiment image
|
| 69 |
if predicted_class == 1:
|
| 70 |
-
st.markdown("
|
| 71 |
st.image("img/positive_emoji.jpg")
|
| 72 |
else:
|
| 73 |
-
st.markdown("
|
| 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,8 +92,8 @@ def main():
|
|
| 92 |
st.write(results_df)
|
| 93 |
|
| 94 |
else:
|
| 95 |
-
st.subheader("
|
| 96 |
-
st.write("
|
| 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()
|