Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,64 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline,
|
3 |
from datasets import load_dataset
|
4 |
import pandas as pd
|
5 |
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
8 |
-
#
|
9 |
@st.cache_resource
|
10 |
def load_data():
|
11 |
dataset = load_dataset("WhiteAngelss/Turkce-Duygu-Analizi-Dataset")
|
12 |
return dataset
|
13 |
|
14 |
dataset = load_data()
|
15 |
-
st.title("Sentiment
|
16 |
|
17 |
-
#
|
18 |
-
st.subheader("
|
19 |
sample_df = pd.DataFrame(dataset['train'])
|
20 |
st.write(sample_df.head())
|
21 |
|
22 |
-
#
|
23 |
model_list = ['WhiteAngelss/entity-word-sentiment-analysis']
|
24 |
-
st.sidebar.header("
|
25 |
model_checkpoint = st.sidebar.radio("", model_list)
|
26 |
|
27 |
-
st.sidebar.write("
|
28 |
st.sidebar.write("")
|
29 |
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
-
if input_method == '
|
34 |
-
example_texts = dataset['train']['text'][:5] #
|
35 |
-
selected_text = st.selectbox('
|
36 |
-
st.subheader("
|
37 |
-
input_text = st.text_area("
|
38 |
-
elif input_method == "
|
39 |
-
st.subheader("
|
40 |
-
input_text = st.text_area('
|
41 |
|
|
|
42 |
@st.cache_resource
|
43 |
-
def
|
44 |
-
model =
|
45 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
46 |
return pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
|
47 |
|
48 |
-
|
|
|
49 |
|
50 |
-
if
|
51 |
-
sentiment_pipeline =
|
52 |
output = sentiment_pipeline(input_text)
|
53 |
|
54 |
-
st.subheader("Sentiment
|
55 |
df = pd.DataFrame(output)
|
56 |
st.dataframe(df)
|
57 |
|
58 |
-
#
|
59 |
sentiment = output[0]['label']
|
60 |
score = output[0]['score']
|
61 |
-
st.write(f"Sentiment: {sentiment} (
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
3 |
from datasets import load_dataset
|
4 |
import pandas as pd
|
5 |
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
8 |
+
# Veriyi yükleme ve ön işleme
|
9 |
@st.cache_resource
|
10 |
def load_data():
|
11 |
dataset = load_dataset("WhiteAngelss/Turkce-Duygu-Analizi-Dataset")
|
12 |
return dataset
|
13 |
|
14 |
dataset = load_data()
|
15 |
+
st.title("Türkçe Sentiment Analizi Uygulaması")
|
16 |
|
17 |
+
# Örnek veri gösterme
|
18 |
+
st.subheader("Örnek Veri")
|
19 |
sample_df = pd.DataFrame(dataset['train'])
|
20 |
st.write(sample_df.head())
|
21 |
|
22 |
+
# Model seçim kısmı
|
23 |
model_list = ['WhiteAngelss/entity-word-sentiment-analysis']
|
24 |
+
st.sidebar.header("Sentiment Analizi Modeli Seçimi")
|
25 |
model_checkpoint = st.sidebar.radio("", model_list)
|
26 |
|
27 |
+
st.sidebar.write("Model detayları için: 'https://huggingface.co/WhiteAngelss/entity-word-sentiment-analysis'")
|
28 |
st.sidebar.write("")
|
29 |
|
30 |
+
# Metin girdi yöntemi seçimi
|
31 |
+
st.subheader("Metin Giriş Yöntemi Seçin")
|
32 |
+
input_method = st.radio("", ('Örneklerden Seç', 'Yeni Metin Yaz veya Yapıştır'))
|
33 |
|
34 |
+
if input_method == 'Örneklerden Seç':
|
35 |
+
example_texts = dataset['train']['text'][:5] # Veri kümesinden örnek metinler
|
36 |
+
selected_text = st.selectbox('Listeden Metin Seçin', example_texts)
|
37 |
+
st.subheader("Analiz Edilecek Metin")
|
38 |
+
input_text = st.text_area("Seçilen Metin", selected_text, height=128, max_chars=None)
|
39 |
+
elif input_method == "Yeni Metin Yaz veya Yapıştır":
|
40 |
+
st.subheader("Analiz Edilecek Metin")
|
41 |
+
input_text = st.text_area('Aşağıya Metin Yazın veya Yapıştırın', value="", height=128, max_chars=None)
|
42 |
|
43 |
+
# Model ve tokenizer'ı yükleme
|
44 |
@st.cache_resource
|
45 |
+
def set_model(model_checkpoint):
|
46 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint) # TensorFlow yerine PyTorch modelini yükleyin
|
47 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
48 |
return pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
|
49 |
|
50 |
+
# Analiz butonu
|
51 |
+
run_button = st.button("Analiz Et")
|
52 |
|
53 |
+
if run_button and input_text:
|
54 |
+
sentiment_pipeline = set_model(model_checkpoint)
|
55 |
output = sentiment_pipeline(input_text)
|
56 |
|
57 |
+
st.subheader("Sentiment Analizi Sonuçları")
|
58 |
df = pd.DataFrame(output)
|
59 |
st.dataframe(df)
|
60 |
|
61 |
+
# Sonuçları kullanıcı dostu bir formatta gösterme
|
62 |
sentiment = output[0]['label']
|
63 |
score = output[0]['score']
|
64 |
+
st.write(f"Sentiment: {sentiment} (Skor: {score:.2f})")
|