Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,18 +6,14 @@ def read_google_sheet(csv_url):
|
|
| 6 |
if not csv_url:
|
| 7 |
return "⚠️ Silakan masukkan URL CSV Google Sheet"
|
| 8 |
|
| 9 |
-
# Baca CSV dari URL
|
| 10 |
df = pd.read_csv(csv_url)
|
| 11 |
-
|
| 12 |
-
# Hapus baris dan kolom yang seluruhnya kosong
|
| 13 |
df = df.dropna(how="all")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
# Konversi DataFrame ke JSON agar lebih mudah diproses oleh AI
|
| 21 |
json_output = df.to_json(orient="records", force_ascii=False, indent=2)
|
| 22 |
return json_output
|
| 23 |
|
|
@@ -29,30 +25,26 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Google Sheet Viewer") as demo:
|
|
| 29 |
gr.Markdown("""
|
| 30 |
# 📊 Google Sheet Viewer
|
| 31 |
**Cara Penggunaan:**
|
| 32 |
-
1. Buka Google Sheet
|
| 33 |
2. Pilih *File > Share > Publish to web*
|
| 34 |
3. Pilih format **CSV** dan publish
|
| 35 |
4. Salin URL CSV yang dihasilkan
|
| 36 |
""")
|
| 37 |
-
|
| 38 |
-
# Input URL menggunakan Textbox
|
| 39 |
url_input = gr.Textbox(
|
| 40 |
label="URL CSV Google Sheet",
|
| 41 |
placeholder="Contoh: https://docs.google.com/spreadsheets/d/.../export?format=csv&gid=0",
|
| 42 |
interactive=True
|
| 43 |
)
|
| 44 |
-
|
| 45 |
-
# Tombol submit
|
| 46 |
submit_button = gr.Button("Tampilkan Data", variant="primary", size="lg")
|
| 47 |
-
|
| 48 |
-
# Output JSON sebagai teks
|
| 49 |
output = gr.Textbox(
|
| 50 |
label="JSON Output (AI Friendly)",
|
| 51 |
lines=10,
|
| 52 |
interactive=False
|
| 53 |
)
|
| 54 |
-
|
| 55 |
-
# Handler untuk tombol submit
|
| 56 |
submit_button.click(
|
| 57 |
fn=read_google_sheet,
|
| 58 |
inputs=url_input,
|
|
|
|
| 6 |
if not csv_url:
|
| 7 |
return "⚠️ Silakan masukkan URL CSV Google Sheet"
|
| 8 |
|
|
|
|
| 9 |
df = pd.read_csv(csv_url)
|
| 10 |
+
# Hapus baris yang seluruhnya kosong
|
|
|
|
| 11 |
df = df.dropna(how="all")
|
| 12 |
+
# Hapus kolom yang tidak memiliki nama (misalnya "Unnamed" atau kolom kosong) dan seluruh nilainya null
|
| 13 |
+
df = df.drop(columns=[col for col in df.columns
|
| 14 |
+
if (("Unnamed" in col or col.strip() == "") and df[col].isna().all())])
|
| 15 |
+
|
| 16 |
+
# Ubah DataFrame ke format JSON yang terstruktur (AI friendly)
|
|
|
|
|
|
|
| 17 |
json_output = df.to_json(orient="records", force_ascii=False, indent=2)
|
| 18 |
return json_output
|
| 19 |
|
|
|
|
| 25 |
gr.Markdown("""
|
| 26 |
# 📊 Google Sheet Viewer
|
| 27 |
**Cara Penggunaan:**
|
| 28 |
+
1. Buka Google Sheet Anda
|
| 29 |
2. Pilih *File > Share > Publish to web*
|
| 30 |
3. Pilih format **CSV** dan publish
|
| 31 |
4. Salin URL CSV yang dihasilkan
|
| 32 |
""")
|
| 33 |
+
|
|
|
|
| 34 |
url_input = gr.Textbox(
|
| 35 |
label="URL CSV Google Sheet",
|
| 36 |
placeholder="Contoh: https://docs.google.com/spreadsheets/d/.../export?format=csv&gid=0",
|
| 37 |
interactive=True
|
| 38 |
)
|
| 39 |
+
|
|
|
|
| 40 |
submit_button = gr.Button("Tampilkan Data", variant="primary", size="lg")
|
| 41 |
+
|
|
|
|
| 42 |
output = gr.Textbox(
|
| 43 |
label="JSON Output (AI Friendly)",
|
| 44 |
lines=10,
|
| 45 |
interactive=False
|
| 46 |
)
|
| 47 |
+
|
|
|
|
| 48 |
submit_button.click(
|
| 49 |
fn=read_google_sheet,
|
| 50 |
inputs=url_input,
|