Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import plotly.express as px
|
|
7 |
import gradio as gr
|
8 |
from dotenv import load_dotenv
|
9 |
from scripts.review_summarizer import analyze_reviews
|
|
|
10 |
|
11 |
load_dotenv()
|
12 |
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')
|
@@ -97,11 +98,33 @@ def scrape_product_comments_v2(url):
|
|
97 |
reviews_df = reviews_df[["Kullanıcı_id", "Kullanıcı Adı", "Yorum", "Tarih", "Yıldız Sayısı"]]
|
98 |
return reviews_df
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def analyze_product(url, progress=gr.Progress()):
|
101 |
try:
|
102 |
# Fetch reviews
|
103 |
progress(0.1, desc="Yorumlar çekiliyor...")
|
104 |
-
df =
|
105 |
|
106 |
if df is None or len(df) == 0:
|
107 |
return None, None, None, None, None, None, None, "Yorumlar çekilemedi. URL'yi kontrol edin."
|
|
|
7 |
import gradio as gr
|
8 |
from dotenv import load_dotenv
|
9 |
from scripts.review_summarizer import analyze_reviews
|
10 |
+
from scrape.trendyol_scraper_origin import scrape_comments as selenium_scrape
|
11 |
|
12 |
load_dotenv()
|
13 |
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')
|
|
|
98 |
reviews_df = reviews_df[["Kullanıcı_id", "Kullanıcı Adı", "Yorum", "Tarih", "Yıldız Sayısı"]]
|
99 |
return reviews_df
|
100 |
|
101 |
+
def scrape_product_comments(url, use_selenium=False):
|
102 |
+
"""
|
103 |
+
Trendyol yorumlarını çeker. Önce API ile dener,
|
104 |
+
başarısız olursa Selenium'a geçer.
|
105 |
+
"""
|
106 |
+
try:
|
107 |
+
if use_selenium:
|
108 |
+
return selenium_scrape(url)
|
109 |
+
|
110 |
+
# Önce API ile deneyelim
|
111 |
+
df = scrape_product_comments_v2(url)
|
112 |
+
if df is not None and len(df) > 0:
|
113 |
+
return df
|
114 |
+
|
115 |
+
# API başarısız olursa Selenium'a geç
|
116 |
+
print("API scraping başarısız oldu, Selenium'a geçiliyor...")
|
117 |
+
return selenium_scrape(url)
|
118 |
+
|
119 |
+
except Exception as e:
|
120 |
+
print(f"Scraping hatası: {str(e)}")
|
121 |
+
return None
|
122 |
+
|
123 |
def analyze_product(url, progress=gr.Progress()):
|
124 |
try:
|
125 |
# Fetch reviews
|
126 |
progress(0.1, desc="Yorumlar çekiliyor...")
|
127 |
+
df = scrape_product_comments(url)
|
128 |
|
129 |
if df is None or len(df) == 0:
|
130 |
return None, None, None, None, None, None, None, "Yorumlar çekilemedi. URL'yi kontrol edin."
|