ihsan66 commited on
Commit
579a34e
1 Parent(s): 345b10c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -26
app.py CHANGED
@@ -1,61 +1,64 @@
1
  import streamlit as st
2
- from transformers import pipeline, TFAutoModelForSequenceClassification, AutoTokenizer
3
  from datasets import load_dataset
4
  import pandas as pd
5
 
6
  st.set_page_config(layout="wide")
7
 
8
- # Load dataset
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 Analysis with Turkish Dataset")
16
 
17
- # Show dataset examples
18
- st.subheader("Sample Data")
19
  sample_df = pd.DataFrame(dataset['train'])
20
  st.write(sample_df.head())
21
 
22
- # Set up model
23
  model_list = ['WhiteAngelss/entity-word-sentiment-analysis']
24
- st.sidebar.header("Select Sentiment Analysis Model")
25
  model_checkpoint = st.sidebar.radio("", model_list)
26
 
27
- st.sidebar.write("For details of models: 'https://huggingface.co/WhiteAngelss/entity-word-sentiment-analysis'")
28
  st.sidebar.write("")
29
 
30
- st.subheader("Select Text Input Method")
31
- input_method = st.radio("", ('Select from Examples', 'Write or Paste New Text'))
 
32
 
33
- if input_method == 'Select from Examples':
34
- example_texts = dataset['train']['text'][:5] # Sample examples from the dataset
35
- selected_text = st.selectbox('Select Text from List', example_texts)
36
- st.subheader("Text to Analyze")
37
- input_text = st.text_area("Selected Text", selected_text, height=128, max_chars=None)
38
- elif input_method == "Write or Paste New Text":
39
- st.subheader("Text to Analyze")
40
- input_text = st.text_area('Write or Paste Text Below', value="", height=128, max_chars=None)
41
 
 
42
  @st.cache_resource
43
- def setModel(model_checkpoint):
44
- model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint)
45
  tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
46
  return pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
47
 
48
- Run_Button = st.button("Run")
 
49
 
50
- if Run_Button and input_text:
51
- sentiment_pipeline = setModel(model_checkpoint)
52
  output = sentiment_pipeline(input_text)
53
 
54
- st.subheader("Sentiment Analysis Results")
55
  df = pd.DataFrame(output)
56
  st.dataframe(df)
57
 
58
- # Display the sentiment in a more user-friendly format
59
  sentiment = output[0]['label']
60
  score = output[0]['score']
61
- st.write(f"Sentiment: {sentiment} (Score: {score:.2f})") # Corrected line with closed parenthesis
 
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})")