Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,17 +9,14 @@ def read_google_sheet(csv_url):
|
|
| 9 |
# Baca CSV dari URL
|
| 10 |
df = pd.read_csv(csv_url)
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
# 1. Hapus baris yang seluruhnya kosong
|
| 14 |
df = df.dropna(how="all")
|
| 15 |
-
# 2. Hapus kolom yang seluruhnya kosong
|
| 16 |
df = df.dropna(axis=1, how="all")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
# Konversi DataFrame ke JSON agar lebih mudah diproses oleh AI
|
| 24 |
json_output = df.to_json(orient="records", force_ascii=False, indent=2)
|
| 25 |
return json_output
|
|
@@ -37,24 +34,24 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Google Sheet Viewer") as demo:
|
|
| 37 |
3. Pilih format **CSV** dan publish
|
| 38 |
4. Salin URL CSV yang dihasilkan
|
| 39 |
""")
|
| 40 |
-
|
| 41 |
# Input URL menggunakan Textbox
|
| 42 |
url_input = gr.Textbox(
|
| 43 |
label="URL CSV Google Sheet",
|
| 44 |
placeholder="Contoh: https://docs.google.com/spreadsheets/d/.../export?format=csv&gid=0",
|
| 45 |
interactive=True
|
| 46 |
)
|
| 47 |
-
|
| 48 |
# Tombol submit
|
| 49 |
submit_button = gr.Button("Tampilkan Data", variant="primary", size="lg")
|
| 50 |
-
|
| 51 |
# Output JSON sebagai teks
|
| 52 |
output = gr.Textbox(
|
| 53 |
label="JSON Output (AI Friendly)",
|
| 54 |
lines=10,
|
| 55 |
interactive=False
|
| 56 |
)
|
| 57 |
-
|
| 58 |
# Handler untuk tombol submit
|
| 59 |
submit_button.click(
|
| 60 |
fn=read_google_sheet,
|
|
|
|
| 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 |
df = df.dropna(axis=1, how="all")
|
| 15 |
+
|
| 16 |
+
# Hapus kolom tanpa nama yang memiliki nilai null di semua baris
|
| 17 |
+
df = df.loc[:, ~df.columns.str.contains("Unnamed")] # Hapus kolom "Unnamed: x"
|
| 18 |
+
df = df.dropna(axis=1, how="all") # Hapus kembali jika masih ada yang null
|
| 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
|
|
|
|
| 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,
|