lint commited on
Commit
f037e2e
·
1 Parent(s): f85dfd4

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +1 -1
  2. __pycache__/query.cpython-310.pyc +0 -0
  3. gsql_app.py +14 -21
  4. query.py +3 -0
  5. requirements.txt +4 -2
Dockerfile CHANGED
@@ -20,4 +20,4 @@ WORKDIR $HOME/app
20
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
21
  COPY --chown=user . $HOME/app
22
 
23
- CMD ["lite", "demo.yaml", "launch", "--server_name", "0.0.0.0", "--server_port", "7860"]
 
20
  # Copy the current directory contents into the container at $HOME/app setting the owner to the user
21
  COPY --chown=user . $HOME/app
22
 
23
+ RUN python gsql_app.py
__pycache__/query.cpython-310.pyc ADDED
Binary file (208 Bytes). View file
 
gsql_app.py CHANGED
@@ -1,18 +1,16 @@
1
- sql_query='''SELECT * FROM input_table
2
- WHERE text LIKE '%curls%';''';
3
  import duckdb
4
  import pandas as pd
5
  import gradio as gr
6
  from datasets import load_dataset
7
  import tempfile
8
- import re
9
-
10
 
11
  max_rows = 20
 
 
12
  df_display_kwargs = dict(
13
  wrap = True,
14
- max_rows = max_rows,
15
- type = "pandas",
16
  row_count = 3,
17
  col_count = 4,
18
  )
@@ -24,13 +22,6 @@ dataset_choices = [
24
 
25
  def apply_sql(input_table, sql_query):
26
 
27
- # Use regex to extract the table name from the SQL query
28
- match = re.search(r"\bFROM\s+(\w+)", sql_query, re.IGNORECASE)
29
- if match:
30
- table_name = match.group(1)
31
-
32
- sql_query = sql_query.replace(table_name, "input_table")
33
-
34
  output_df = duckdb.query(sql_query).to_df()
35
 
36
  return output_df
@@ -39,18 +30,18 @@ def display_dataset(dataset_id):
39
 
40
  dataset = load_dataset(dataset_id, split="train")
41
  df = dataset.to_pandas()
42
- return df, df
 
43
 
44
  def upload_dataset(dataset_file):
45
 
46
  if dataset_file is None:
47
  return None, None
 
 
 
48
 
49
- print(dataset_file.name)
50
-
51
- df = pd.read_csv(dataset_file.name)
52
-
53
- return df, df
54
 
55
 
56
  def process_dataset(full_dataset, sql_query):
@@ -69,8 +60,7 @@ theme = gr.themes.Soft(
69
  neutral_hue="slate",
70
  )
71
 
72
-
73
- with gr.Blocks(analytics_enabled=False, theme=theme) as demo:
74
  full_dataset = gr.State()
75
 
76
  with gr.Column():
@@ -123,3 +113,6 @@ with gr.Blocks(analytics_enabled=False, theme=theme) as demo:
123
  )
124
  demo.load(**toggle_dark_mode_args)
125
  dark_mode_btn.click(**toggle_dark_mode_args)
 
 
 
 
1
+
 
2
  import duckdb
3
  import pandas as pd
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 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ sql_query='''
2
+ SELECT * FROM input_table WHERE text LIKE '%the rock%'
3
+ '''
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
- gradio==3.32
2
- liteobj==0.0.7
 
 
 
1
+ gradio==3.33.1
2
+ pandas>=2.0
3
+ duckdb>=0.8.0
4
+ datasets