enesmanan commited on
Commit
4b29a3a
·
verified ·
1 Parent(s): 99d7b92
Files changed (1) hide show
  1. app.py +53 -31
app.py CHANGED
@@ -7,43 +7,65 @@ import plotly.graph_objects as go
7
  import os
8
  import subprocess
9
 
10
- # ChromeDriver kurulumu için fonksiyon
11
  def setup_chrome():
12
- # Chrome kurulumu
13
- os.system('apt-get update && apt-get install -y wget gnupg')
14
- os.system('wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -')
15
- os.system('echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list')
16
- os.system('apt-get update && apt-get install -y google-chrome-stable')
17
-
18
- # ChromeDriver kurulumu
19
- chrome_version = subprocess.check_output(['google-chrome', '--version']).decode().strip().split()[2].split('.')[0]
20
- os.system(f'wget -q "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_{chrome_version}" -O chrome_version')
21
- os.system('wget -q "https://chromedriver.storage.googleapis.com/$(cat chrome_version)/chromedriver_linux64.zip"')
22
- os.system('unzip chromedriver_linux64.zip && mv chromedriver /usr/local/bin/ && chmod +x /usr/local/bin/chromedriver')
23
-
24
- # Ana uygulama başlamadan önce Chrome kurulumunu yap
25
- setup_chrome()
 
 
 
 
 
 
 
26
 
27
  class ReviewAnalysisApp:
28
  def __init__(self):
29
- self.analyzer = ReviewAnalyzer()
 
 
 
 
30
 
31
  def analyze_url(self, url):
32
- # Yorumları çek
33
- df = scrape_reviews(url)
34
-
35
- # Sentiment analizi yap
36
- analyzed_df = self.analyzer.analyze_reviews(df)
37
-
38
- # Özet oluştur
39
- summary = self.analyzer.generate_summary(analyzed_df)
40
-
41
- # Grafikleri oluştur
42
- fig1 = self.create_sentiment_distribution(analyzed_df)
43
- fig2 = self.create_rating_distribution(analyzed_df)
44
- fig3 = self.create_sentiment_by_rating(analyzed_df)
45
-
46
- return summary, fig1, fig2, fig3
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  def create_sentiment_distribution(self, df):
49
  fig = px.pie(df,
 
7
  import os
8
  import subprocess
9
 
 
10
  def setup_chrome():
11
+ """Chrome ve ChromeDriver kurulumu"""
12
+ try:
13
+ # Chrome kurulumu
14
+ os.system('apt-get update')
15
+ os.system('apt-get install -y wget unzip')
16
+ os.system('wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -')
17
+ os.system('echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list')
18
+ os.system('apt-get update')
19
+ os.system('apt-get install -y google-chrome-stable')
20
+
21
+ # ChromeDriver kurulumu
22
+ chrome_version = subprocess.check_output(['google-chrome', '--version']).decode().strip().split()[2].split('.')[0]
23
+ os.system(f'wget -q "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_{chrome_version}" -O chrome_version')
24
+ os.system(f'wget -q "https://chromedriver.storage.googleapis.com/$(cat chrome_version)/chromedriver_linux64.zip"')
25
+ os.system('unzip chromedriver_linux64.zip')
26
+ os.system('mv chromedriver /usr/local/bin/')
27
+ os.system('chmod +x /usr/local/bin/chromedriver')
28
+ print("Chrome ve ChromeDriver başarıyla kuruldu!")
29
+
30
+ except Exception as e:
31
+ print(f"Chrome kurulumunda hata: {str(e)}")
32
 
33
  class ReviewAnalysisApp:
34
  def __init__(self):
35
+ try:
36
+ setup_chrome() # Uygulama başlatılırken Chrome'u kur
37
+ self.analyzer = ReviewAnalyzer()
38
+ except Exception as e:
39
+ print(f"Uygulama başlatılırken hata: {str(e)}")
40
 
41
  def analyze_url(self, url):
42
+ try:
43
+ if not url or not url.startswith("https://www.trendyol.com/"):
44
+ return "Lütfen geçerli bir Trendyol ürün yorumları URL'si girin.", None, None, None
45
+
46
+ print("Yorumlar çekiliyor...")
47
+ df = scrape_reviews(url)
48
+
49
+ if df.empty:
50
+ return "Yorumlar çekilemedi. Lütfen URL'yi kontrol edin.", None, None, None
51
+
52
+ print("Sentiment analizi yapılıyor...")
53
+ analyzed_df = self.analyzer.analyze_reviews(df)
54
+
55
+ print("Özet oluşturuluyor...")
56
+ summary = self.analyzer.generate_summary(analyzed_df)
57
+
58
+ print("Grafikler oluşturuluyor...")
59
+ fig1 = self.create_sentiment_distribution(analyzed_df)
60
+ fig2 = self.create_rating_distribution(analyzed_df)
61
+ fig3 = self.create_sentiment_by_rating(analyzed_df)
62
+
63
+ return summary, fig1, fig2, fig3
64
+
65
+ except Exception as e:
66
+ error_msg = f"Analiz sırasında hata oluştu: {str(e)}"
67
+ print(error_msg)
68
+ return error_msg, None, None, None
69
 
70
  def create_sentiment_distribution(self, df):
71
  fig = px.pie(df,