Spaces:
Runtime error
Runtime error
azizbarank
commited on
Commit
•
688e382
1
Parent(s):
3924e7a
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install torch")
|
3 |
+
os.system("pip install transformers")
|
4 |
+
os.system("pip install sentencepiece")
|
5 |
+
|
6 |
+
import streamlit as st
|
7 |
+
from transformers import pipeline
|
8 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
9 |
+
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("azizbarank/distilbert-base-turkish-cased-sentiment")
|
11 |
+
model = AutoModelForSequenceClassification.from_pretrained("azizbarank/distilbert-base-turkish-cased-sentiment")
|
12 |
+
|
13 |
+
def classify(text):
|
14 |
+
cls= pipeline("text-classification",model=model, tokenizer=tokenizer)
|
15 |
+
return cls(text)[0]['label']
|
16 |
+
|
17 |
+
|
18 |
+
site_header = st.container()
|
19 |
+
text_input = st.container()
|
20 |
+
model_results = st.container()
|
21 |
+
|
22 |
+
with site_header:
|
23 |
+
st.title('Turkish Sentiment Analysis 😀😠')
|
24 |
+
st.markdown(
|
25 |
+
"""
|
26 |
+
[Distilled Turkish BERT model](https://huggingface.co/dbmdz/distilbert-base-turkish-cased) that I fine-tuned on the [sepidmnorozy/Turkish_sentiment](https://huggingface.co/datasets/sepidmnorozy/Turkish_sentiment) dataset that is heavily based on different reviews about services/places.
|
27 |
+
|
28 |
+
For more information on the dataset:
|
29 |
+
|
30 |
+
* [Hugging Face](https://huggingface.co/datasets/sepidmnorozy/Turkish_sentiment)
|
31 |
+
"""
|
32 |
+
)
|
33 |
+
|
34 |
+
with text_input:
|
35 |
+
st.header('Is Your Review Considered Positive or Negative?')
|
36 |
+
st.write("""*Please note that predictions are based on how the model was trained, so it may not be an accurate representation.*""")
|
37 |
+
user_text = st.text_input('Enter Text', max_chars=300)
|
38 |
+
|
39 |
+
with model_results:
|
40 |
+
st.subheader('Prediction:')
|
41 |
+
if user_text:
|
42 |
+
prediction = classify(user_text)
|
43 |
+
|
44 |
+
if prediction == "LABEL_0":
|
45 |
+
st.subheader('**Negative**')
|
46 |
+
else:
|
47 |
+
st.subheader('**Positive**')
|
48 |
+
st.text('')
|