Layout fixes and removes checkboxes
Browse files
app.py
CHANGED
@@ -3,7 +3,8 @@ import pandas as pd
|
|
3 |
import duckdb
|
4 |
|
5 |
PARQUET_FILES = {
|
6 |
-
"
|
|
|
7 |
}
|
8 |
|
9 |
preset_values = [
|
@@ -13,23 +14,16 @@ preset_values = [
|
|
13 |
"1girl, elaina (majo no tabitabi), majo no tabitabi"
|
14 |
]
|
15 |
|
16 |
-
def search_data(search_term, selected_file
|
17 |
try:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
results = con.execute(f"SELECT * FROM my_table WHERE lower(teks) LIKE '%{search_term.lower()}%'").fetchdf()
|
23 |
-
else:
|
24 |
-
search_terms_sql = " OR ".join([f"lower(teks) LIKE '%{term.lower()}%'" for term in preset_values])
|
25 |
-
results = con.execute(f"SELECT * FROM my_table WHERE {search_terms_sql}").fetchdf()
|
26 |
-
con.close()
|
27 |
else:
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
else:
|
32 |
-
results = df[df['teks'].str.lower().str.contains("|".join(preset_values).lower(), na=False)]
|
33 |
|
34 |
if len(results.columns) > 12:
|
35 |
results = results.iloc[:, :12]
|
@@ -42,40 +36,34 @@ def search_data(search_term, selected_file, use_duckdb=False):
|
|
42 |
if __name__ == "__main__":
|
43 |
with gr.Blocks() as app:
|
44 |
gr.Markdown("## Text Search for Animagine tag characters")
|
45 |
-
with gr.Row(): #
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
63 |
-
inputs = [search_input, file_dropdown
|
64 |
search_input.change(
|
65 |
fn=search_data,
|
66 |
inputs=inputs,
|
67 |
outputs=search_output,
|
68 |
)
|
69 |
-
file_dropdown.change(
|
70 |
-
fn=search_data,
|
71 |
-
inputs=inputs,
|
72 |
-
outputs=search_output,
|
73 |
-
)
|
74 |
-
use_duckdb_checkbox.change( #Menambahkan event change untuk checkbox
|
75 |
fn=search_data,
|
76 |
inputs=inputs,
|
77 |
outputs=search_output,
|
78 |
)
|
79 |
|
80 |
-
|
81 |
app.launch()
|
|
|
3 |
import duckdb
|
4 |
|
5 |
PARQUET_FILES = {
|
6 |
+
"File 1": 'data1.parquet', # Ganti dengan path file Anda
|
7 |
+
"File 2": 'data2.parquet' # Ganti dengan path file Anda
|
8 |
}
|
9 |
|
10 |
preset_values = [
|
|
|
14 |
"1girl, elaina (majo no tabitabi), majo no tabitabi"
|
15 |
]
|
16 |
|
17 |
+
def search_data(search_term, selected_file):
|
18 |
try:
|
19 |
+
con = duckdb.connect(database=':memory:', read_only=False)
|
20 |
+
con.execute(f"CREATE TABLE my_table AS SELECT * FROM read_parquet('{PARQUET_FILES[selected_file]}')")
|
21 |
+
if search_term.strip():
|
22 |
+
results = con.execute(f"SELECT * FROM my_table WHERE lower(teks) LIKE '%{search_term.lower()}%'").fetchdf()
|
|
|
|
|
|
|
|
|
|
|
23 |
else:
|
24 |
+
search_terms_sql = " OR ".join([f"lower(teks) LIKE '%{term.lower()}%'" for term in preset_values])
|
25 |
+
results = con.execute(f"SELECT * FROM my_table WHERE {search_terms_sql}").fetchdf()
|
26 |
+
con.close()
|
|
|
|
|
27 |
|
28 |
if len(results.columns) > 12:
|
29 |
results = results.iloc[:, :12]
|
|
|
36 |
if __name__ == "__main__":
|
37 |
with gr.Blocks() as app:
|
38 |
gr.Markdown("## Text Search for Animagine tag characters")
|
39 |
+
with gr.Row(): # Menggunakan Row untuk layout horizontal
|
40 |
+
with gr.Column(): # Kolom untuk input pencarian
|
41 |
+
search_input = gr.Textbox(
|
42 |
+
label="Search for characters or series:",
|
43 |
+
placeholder="sousou no frieren",
|
44 |
+
)
|
45 |
+
with gr.Column(): # Kolom untuk dropdown
|
46 |
+
file_dropdown = gr.Dropdown(
|
47 |
+
choices=list(PARQUET_FILES.keys()),
|
48 |
+
label="Select Parquet File",
|
49 |
+
value=list(PARQUET_FILES.keys())[0], # Default value
|
50 |
+
)
|
51 |
+
search_output = gr.Dataframe( # Output di luar row, di bawahnya
|
52 |
+
label="Search Results",
|
53 |
+
value=pd.DataFrame({'Characters tag': preset_values}),
|
54 |
+
headers="auto",
|
55 |
+
)
|
56 |
|
57 |
+
inputs = [search_input, file_dropdown]
|
58 |
search_input.change(
|
59 |
fn=search_data,
|
60 |
inputs=inputs,
|
61 |
outputs=search_output,
|
62 |
)
|
63 |
+
file_dropdown.change(
|
|
|
|
|
|
|
|
|
|
|
64 |
fn=search_data,
|
65 |
inputs=inputs,
|
66 |
outputs=search_output,
|
67 |
)
|
68 |
|
|
|
69 |
app.launch()
|