ihsan66 commited on
Commit
01642a5
·
verified ·
1 Parent(s): 7db8e94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -15
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from transformers import pipeline, TFAutoModelForSequenceClassification, AutoTokenizer
3
  from datasets import load_dataset
4
  import pandas as pd
5
 
@@ -12,7 +12,7 @@ def load_data():
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")
@@ -21,7 +21,7 @@ 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'")
@@ -43,22 +43,44 @@ elif input_method == "Yeni Metin Yaz veya Yapıştır":
43
  # Model ve tokenizer'ı yükleme
44
  @st.cache_resource
45
  def set_model(model_checkpoint):
46
- model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint, from_tf=True) # TensorFlow 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})")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline, TFAutoModelForSequenceClassification, AutoTokenizer, TFAutoModelForTokenClassification
3
  from datasets import load_dataset
4
  import pandas as pd
5
 
 
12
  return dataset
13
 
14
  dataset = load_data()
15
+ st.title("Türkçe Sentiment Analizi ve Entity Tanıma Uygulaması")
16
 
17
  # Örnek veri gösterme
18
  st.subheader("Örnek Veri")
 
21
 
22
  # Model seçim kısmı
23
  model_list = ['WhiteAngelss/entity-word-sentiment-analysis']
24
+ st.sidebar.header("Model 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'")
 
43
  # Model ve tokenizer'ı yükleme
44
  @st.cache_resource
45
  def set_model(model_checkpoint):
46
+ sentiment_model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint, from_tf=True)
47
  tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
48
+
49
+ # Named Entity Recognition (NER) için model
50
+ ner_model = TFAutoModelForTokenClassification.from_pretrained('dbmdz/bert-large-cased-finetuned-conll03-english', from_tf=True)
51
+ ner_tokenizer = AutoTokenizer.from_pretrained('dbmdz/bert-large-cased-finetuned-conll03-english')
52
+
53
+ return {
54
+ 'sentiment_pipeline': pipeline('sentiment-analysis', model=sentiment_model, tokenizer=tokenizer),
55
+ 'ner_pipeline': pipeline('ner', model=ner_model, tokenizer=ner_tokenizer)
56
+ }
57
 
58
  # Analiz butonu
59
  run_button = st.button("Analiz Et")
60
 
61
  if run_button and input_text:
62
+ pipelines = set_model(model_checkpoint)
 
63
 
64
+ # Named Entity Recognition (NER) yapma
65
+ ner_pipeline = pipelines['ner_pipeline']
66
+ ner_output = ner_pipeline(input_text)
67
+
68
+ # Sentiment analizi yapma
69
+ sentiment_pipeline = pipelines['sentiment_pipeline']
70
+
71
+ # Entity bazında sonuçları toplama
72
+ results = []
73
+ for entity in ner_output:
74
+ entity_text = entity['word']
75
+ sentiment_output = sentiment_pipeline(entity_text)
76
+
77
+ results.append({
78
+ 'Entity': entity_text,
79
+ 'Entity Sınıfı': entity['entity'],
80
+ 'Sentiment': sentiment_output[0]['label'],
81
+ 'Skor': sentiment_output[0]['score']
82
+ })
83
+
84
+ st.subheader("Entity ve Sentiment Analizi Sonuçları")
85
+ results_df = pd.DataFrame(results)
86
+ st.write(results_df)