Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- __pycache__/query.cpython-310.pyc +0 -0
- gsql_app.py +12 -18
- query.py +1 -1
__pycache__/query.cpython-310.pyc
ADDED
Binary file (208 Bytes). View file
|
|
gsql_app.py
CHANGED
@@ -4,14 +4,13 @@ import pandas as pd
|
|
4 |
import gradio as gr
|
5 |
from datasets import load_dataset
|
6 |
import tempfile
|
7 |
-
import re
|
8 |
from query import sql_query
|
9 |
|
10 |
max_rows = 20
|
|
|
|
|
11 |
df_display_kwargs = dict(
|
12 |
wrap = True,
|
13 |
-
max_rows = max_rows,
|
14 |
-
type = "pandas",
|
15 |
row_count = 3,
|
16 |
col_count = 4,
|
17 |
)
|
@@ -23,13 +22,6 @@ dataset_choices = [
|
|
23 |
|
24 |
def apply_sql(input_table, sql_query):
|
25 |
|
26 |
-
# Use regex to extract the table name from the SQL query
|
27 |
-
match = re.search(r"\bFROM\s+(\w+)", sql_query, re.IGNORECASE)
|
28 |
-
if match:
|
29 |
-
table_name = match.group(1)
|
30 |
-
|
31 |
-
sql_query = sql_query.replace(table_name, "input_table")
|
32 |
-
|
33 |
output_df = duckdb.query(sql_query).to_df()
|
34 |
|
35 |
return output_df
|
@@ -38,18 +30,18 @@ def display_dataset(dataset_id):
|
|
38 |
|
39 |
dataset = load_dataset(dataset_id, split="train")
|
40 |
df = dataset.to_pandas()
|
41 |
-
|
|
|
42 |
|
43 |
def upload_dataset(dataset_file):
|
44 |
|
45 |
if dataset_file is None:
|
46 |
return None, None
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
df = pd.read_csv(dataset_file.name)
|
51 |
-
|
52 |
-
return df, df
|
53 |
|
54 |
|
55 |
def process_dataset(full_dataset, sql_query):
|
@@ -68,8 +60,7 @@ theme = gr.themes.Soft(
|
|
68 |
neutral_hue="slate",
|
69 |
)
|
70 |
|
71 |
-
|
72 |
-
with gr.Blocks(analytics_enabled=False, theme=theme) as demo:
|
73 |
full_dataset = gr.State()
|
74 |
|
75 |
with gr.Column():
|
@@ -122,3 +113,6 @@ with gr.Blocks(analytics_enabled=False, theme=theme) as demo:
|
|
122 |
)
|
123 |
demo.load(**toggle_dark_mode_args)
|
124 |
dark_mode_btn.click(**toggle_dark_mode_args)
|
|
|
|
|
|
|
|
4 |
import gradio as gr
|
5 |
from datasets import load_dataset
|
6 |
import tempfile
|
|
|
7 |
from query import sql_query
|
8 |
|
9 |
max_rows = 20
|
10 |
+
max_cols = None
|
11 |
+
|
12 |
df_display_kwargs = dict(
|
13 |
wrap = True,
|
|
|
|
|
14 |
row_count = 3,
|
15 |
col_count = 4,
|
16 |
)
|
|
|
22 |
|
23 |
def apply_sql(input_table, sql_query):
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
output_df = duckdb.query(sql_query).to_df()
|
26 |
|
27 |
return output_df
|
|
|
30 |
|
31 |
dataset = load_dataset(dataset_id, split="train")
|
32 |
df = dataset.to_pandas()
|
33 |
+
display_df = df.iloc[:max_rows, :max_cols]
|
34 |
+
return display_df, df
|
35 |
|
36 |
def upload_dataset(dataset_file):
|
37 |
|
38 |
if dataset_file is None:
|
39 |
return None, None
|
40 |
+
|
41 |
+
df = pd.read_csv(dataset_file.name).iloc[:max_rows, :max_cols]
|
42 |
+
display_df = df.iloc[:max_rows, :max_cols]
|
43 |
|
44 |
+
return display_df, df
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
def process_dataset(full_dataset, sql_query):
|
|
|
60 |
neutral_hue="slate",
|
61 |
)
|
62 |
|
63 |
+
with gr.Blocks(theme=theme) as demo:
|
|
|
64 |
full_dataset = gr.State()
|
65 |
|
66 |
with gr.Column():
|
|
|
113 |
)
|
114 |
demo.load(**toggle_dark_mode_args)
|
115 |
dark_mode_btn.click(**toggle_dark_mode_args)
|
116 |
+
|
117 |
+
if __name__ == "__main__":
|
118 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
query.py
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
sql_query='''
|
2 |
-
SELECT * FROM input_table WHERE text LIKE '%
|
3 |
'''
|
|
|
1 |
sql_query='''
|
2 |
+
SELECT * FROM input_table WHERE text LIKE '%conan%'
|
3 |
'''
|