fixx
Browse files
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 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
class ReviewAnalysisApp:
|
| 28 |
def __init__(self):
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def analyze_url(self, url):
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|