Spaces:
Runtime error
Runtime error
File size: 1,870 Bytes
55c696a 7115450 55c696a 8fd30d2 55c696a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # install dulu:
# pip install google-play-scraper pandas gradio
import os
os.system('pip install google-play-scraper')
from google_play_scraper import reviews_all
import pandas as pd
import gradio as gr
import tempfile
import os
def scrape_reviews(app_id, language, country):
try:
# Ambil semua ulasan
reviews = reviews_all(
app_id,
sleep_milliseconds=0,
lang=language,
country=country
)
if not reviews:
return None, "Tidak ada ulasan ditemukan."
# Konversi ke DataFrame
df = pd.DataFrame(reviews)
df_filtered = df[['at', 'score', 'content']]
df_filtered.columns = ['Tanggal', 'Rating', 'Ulasan']
# Simpan sementara ke CSV
temp_dir = tempfile.mkdtemp()
file_path = os.path.join(temp_dir, f"ulasan_{app_id}.csv")
df_filtered.to_csv(file_path, index=False, encoding='utf-8-sig')
return file_path, f"Berhasil mengambil {len(df_filtered)} ulasan."
except Exception as e:
return None, f"Error: {str(e)}"
# Buat UI Gradio
with gr.Blocks() as demo:
gr.Markdown("# 📱 Scraper Ulasan Google Play Store")
gr.Markdown("Masukkan **App ID** Google Play, pilih bahasa dan negara, lalu unduh CSV ulasan.")
with gr.Row():
app_id_input = gr.Textbox(label="App ID", value="com.ruangguru.livestudents")
lang_input = gr.Textbox(label="Bahasa", value="id")
country_input = gr.Textbox(label="Negara", value="id")
scrape_button = gr.Button("Mulai Scraping")
output_file = gr.File(label="Download CSV", type="filepath")
status_output = gr.Textbox(label="Status", interactive=False)
scrape_button.click(
scrape_reviews,
inputs=[app_id_input, lang_input, country_input],
outputs=[output_file, status_output]
)
demo.launch() |