Upload 2 files
Browse files
gg.png
ADDED
![]() |
ilk2.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#writefile app.py
|
2 |
+
import streamlit as st
|
3 |
+
import smtplib
|
4 |
+
from email.mime.text import MIMEText
|
5 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, AutoModelForSequenceClassification, pipeline
|
6 |
+
import re
|
7 |
+
from pydantic import BaseModel, Field
|
8 |
+
from PIL import Image
|
9 |
+
|
10 |
+
ner_model_name = "Gorengoz/bert-based-Turkish-NER-wikiann"
|
11 |
+
sentiment_model_name = "Gorengoz/bert-turkish-sentiment-analysis-cased"
|
12 |
+
|
13 |
+
# Initialize tokenizers and models for NER
|
14 |
+
ner_tokenizer = AutoTokenizer.from_pretrained(ner_model_name)
|
15 |
+
ner_model = AutoModelForTokenClassification.from_pretrained(ner_model_name)
|
16 |
+
|
17 |
+
# Initialize tokenizers and models for Sentiment Analysis
|
18 |
+
sentiment_tokenizer = AutoTokenizer.from_pretrained(sentiment_model_name)
|
19 |
+
sentiment_model = AutoModelForSequenceClassification.from_pretrained(sentiment_model_name)
|
20 |
+
|
21 |
+
# Create pipelines for NER and Sentiment Analysis
|
22 |
+
ner_pipeline = pipeline("token-classification", model=ner_model, tokenizer=ner_tokenizer)
|
23 |
+
sentiment_pipeline = pipeline("text-classification", model=sentiment_model, tokenizer=sentiment_tokenizer)
|
24 |
+
|
25 |
+
|
26 |
+
label_mapping = {
|
27 |
+
"LABEL_0": "olumlu",
|
28 |
+
"LABEL_1": "nötr",
|
29 |
+
"LABEL_2": "olumsuz"
|
30 |
+
}
|
31 |
+
|
32 |
+
class SentimentResult(BaseModel):
|
33 |
+
entity: str
|
34 |
+
sentiment: str
|
35 |
+
|
36 |
+
class AnalysisResponse(BaseModel):
|
37 |
+
entity_list: list
|
38 |
+
sentiment_list: list
|
39 |
+
# Her entity için cümleleri parçalama
|
40 |
+
def get_entity_sentences(entity: str, sentences: list) -> list:
|
41 |
+
return [sent for sent in sentences if entity in sent]
|
42 |
+
|
43 |
+
def predict(review):
|
44 |
+
# NER modelini kullanarak entity'leri bulma
|
45 |
+
entities = ner_pipeline(review, aggregation_strategy="simple")
|
46 |
+
|
47 |
+
unique_entities = set([entity['word'] for entity in entities])
|
48 |
+
|
49 |
+
# Cümleleri hem '.' hem de ',' ile bölme
|
50 |
+
sentences = re.split(r'[.,]', review)
|
51 |
+
sentences = [sentence.strip() for sentence in sentences if sentence.strip()]
|
52 |
+
|
53 |
+
# Sentiment modelimizi kullanma
|
54 |
+
entity_sentiments = {}
|
55 |
+
for entity in unique_entities:
|
56 |
+
entity_sentences = get_entity_sentences(entity, sentences)
|
57 |
+
sentiments = [sentiment_pipeline(sentence) for sentence in entity_sentences]
|
58 |
+
|
59 |
+
flattened_sentiments = [item for sublist in sentiments for item in sublist]
|
60 |
+
|
61 |
+
# Entitilerin sentimentini bulma
|
62 |
+
if flattened_sentiments:
|
63 |
+
sentiment_scores = [sent['label'] for sent in flattened_sentiments]
|
64 |
+
mapped_sentiments = [label_mapping.get(label, 'unknown') for label in sentiment_scores]
|
65 |
+
sentiment = max(set(mapped_sentiments), key=mapped_sentiments.count) # Bir marka için farklı sentimentler bulunduğunda en baskın olanı kabul etme.
|
66 |
+
else:
|
67 |
+
sentiment = 'nötr'
|
68 |
+
|
69 |
+
entity_sentiments[entity] = sentiment
|
70 |
+
|
71 |
+
entity_list=list(entity_sentiments.keys())
|
72 |
+
sentiment_list=list(entity_sentiments.values())
|
73 |
+
|
74 |
+
return entity_list, sentiment_list
|
75 |
+
|
76 |
+
|
77 |
+
def send_email(to_address, subject, body):
|
78 |
+
# Configure email details
|
79 |
+
from_address = '[email protected]'
|
80 |
+
smtp_server = 'smtp.gmail.com'
|
81 |
+
smtp_port = 587
|
82 |
+
smtp_user = '[email protected]'
|
83 |
+
smtp_password = 'jtbb gfbd rfix thoe'
|
84 |
+
|
85 |
+
# Create email message
|
86 |
+
msg = MIMEText(body, 'plain', 'utf-8')
|
87 |
+
msg['Subject'] = subject
|
88 |
+
msg['From'] = from_address
|
89 |
+
msg['To'] = to_address
|
90 |
+
|
91 |
+
# Send email
|
92 |
+
with smtplib.SMTP(smtp_server, smtp_port) as server:
|
93 |
+
server.starttls()
|
94 |
+
server.login(smtp_user, smtp_password)
|
95 |
+
server.sendmail(from_address, to_address, msg.as_string())
|
96 |
+
|
97 |
+
def send_customer_response(customer_email, sentiment):
|
98 |
+
if sentiment == "olumlu":
|
99 |
+
subject = "Geri Bildiriminiz İçin Teşekkürler"
|
100 |
+
body = (f"Merhaba,\n\n"
|
101 |
+
f"Geri bildiriminiz tarafımıza ulaştı ve olumlu değerlendirildi.\n\n"
|
102 |
+
f"Memnuniyetiniz için teşekkür ederiz. Düşünceleriniz bizim için çok değerlidir ve bu tür olumlu yorumlar bizi motive eder. Size en iyi hizmeti sunmak için sürekli olarak çalışıyoruz.\n\n"
|
103 |
+
f"Herhangi bir ek bilgiye ihtiyacınız olursa, lütfen bizimle iletişime geçin.\n\n"
|
104 |
+
f"Saygılarımızla,\n")
|
105 |
+
else:
|
106 |
+
subject = "Şikayetiniz Alındı ve Üzerinde Çalışıyoruz"
|
107 |
+
body = (f"Merhaba,\n\n"
|
108 |
+
f"Şikayetiniz tarafımıza ulaştı ve değerlendirilmek üzere alındı.\n\n"
|
109 |
+
f"Şikayetinizle ilgili olarak size geri dönüş yapacağız ve sorunun çözümü için gerekli adımları atacağız.\n\n"
|
110 |
+
f"Herhangi bir ek bilgiye ihtiyacınız olursa, lütfen bizimle iletişime geçin.\n\n"
|
111 |
+
f"İlginiz için teşekkür ederiz.\n\n"
|
112 |
+
f"Saygılarımızla,\n")
|
113 |
+
|
114 |
+
send_email(customer_email, subject, body)
|
115 |
+
|
116 |
+
|
117 |
+
def process_complaints(complaint):
|
118 |
+
organizations, sentiment = predict(complaint)
|
119 |
+
for org in organizations:
|
120 |
+
# Construct email subject and body
|
121 |
+
subject = f"{org} Hakkında Müşteri Geri Bildirimi"
|
122 |
+
body = (f"Merhaba {org} Ekibi,\n\n"
|
123 |
+
f"Müşterilerimizden gelen aşağıdaki yorum tarafımıza iletilmiştir:\n\n"
|
124 |
+
f"Yorum: {complaint}\n\n"
|
125 |
+
f"Analiz: {sentiment[organizations.index(org)]}\n\n"
|
126 |
+
f"Geri bildirimleri ele alıp değerlendirdiğiniz için teşekkür ederiz. Bu konuda gerekli aksiyonları alacağınızdan eminiz. Herhangi bir ek bilgiye "
|
127 |
+
f"ihtiyacınız olursa lütfen bizimle iletişime geçin.\n\n"
|
128 |
+
f"İyi çalışmalar dileriz.\n\n"
|
129 |
+
f"Saygılarımızla,\n")
|
130 |
+
# Use the fixed brand email address
|
131 |
+
to_address = "[email protected]"
|
132 |
+
send_email(to_address, subject, body)
|
133 |
+
|
134 |
+
# Sending response to the customer
|
135 |
+
send_customer_response(customer_email, sentiment)
|
136 |
+
|
137 |
+
# Streamlit application
|
138 |
+
col1, col2, col3 = st.columns(3)
|
139 |
+
# Merkezi konumlandırma için bir sütun düzeni kullanma
|
140 |
+
col1, col2, col3 = st.columns([1, 3, 2]) # Oranları isteğinize göre ayarlayabilirsiniz
|
141 |
+
|
142 |
+
with col1:
|
143 |
+
st.write(" ")
|
144 |
+
with col2:
|
145 |
+
image = Image.open('gg.png')
|
146 |
+
st.image(image, width=400)
|
147 |
+
with col3:
|
148 |
+
st.write(" ")
|
149 |
+
|
150 |
+
st.title('Müşteri Geri Bildirim Yönetimi')
|
151 |
+
|
152 |
+
# st.header('Yorum Bildir')
|
153 |
+
st.write("Müşteri/Tüketici Geri Bildirimi Yönetim Sistemi ile memnuniyet veya şikâyetlerinizi tarafımıza bildirebilirsiniz. ")
|
154 |
+
st.write("E-posta bilgilerinizi girerek 'Şikayet Gönder' butonuna tıklamanız dahilinde form verileri doğrulanır. ")
|
155 |
+
st.write("Geri bildirimizde belirttiğiniz her bir organizasyona memnuniyet veya şikâyetiniz iletildikten sonra; tarafınıza mail yoluyla bilgilendirme yapılır.")
|
156 |
+
with st.form(key='complaint_form'):
|
157 |
+
complaint_text = st.text_area("Yorum Metni")
|
158 |
+
customer_email = st.text_input("Müşteri E-Posta Adresi")
|
159 |
+
submit_button = st.form_submit_button(label='Gönder')
|
160 |
+
|
161 |
+
if submit_button:
|
162 |
+
if complaint_text and customer_email:
|
163 |
+
process_complaints(complaint_text)
|
164 |
+
st.success('Geri bildirim başarıyla işlendi ve e-postalar gönderildi.')
|
165 |
+
else:
|
166 |
+
st.error('Lütfen tüm alanları doldurduğunuzdan emin olun.')
|
167 |
+
|
168 |
+
|
169 |
+
# Trendyol sitesinden aldığım ürünü çok beğendim. Ancak kargolama berbattı @ArasKargo
|