Commit
·
07850ea
1
Parent(s):
f6aec2d
feat: add basic working version
Browse files
app.py
CHANGED
|
@@ -35,15 +35,17 @@ def get_iframe(hub_repo_id, sql_query=None):
|
|
| 35 |
def get_column_info(hub_repo_id):
|
| 36 |
url: str = f"https://datasets-server.huggingface.co/info?dataset={hub_repo_id}"
|
| 37 |
response = requests.get(url)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
-
def query_dataset(hub_repo_id,
|
| 47 |
messages = [
|
| 48 |
{
|
| 49 |
"role": "system",
|
|
@@ -51,9 +53,7 @@ def query_dataset(hub_repo_id, description, features, query):
|
|
| 51 |
},
|
| 52 |
{
|
| 53 |
"role": "user",
|
| 54 |
-
"content": f"""
|
| 55 |
-
{description}
|
| 56 |
-
|
| 57 |
# Features
|
| 58 |
{features}
|
| 59 |
|
|
@@ -84,12 +84,9 @@ with gr.Blocks() as demo:
|
|
| 84 |
with gr.Row():
|
| 85 |
search_out = gr.HTML(label="Search Results")
|
| 86 |
with gr.Row():
|
| 87 |
-
|
| 88 |
-
label="Description", placeholder="Description from dataset or project page"
|
| 89 |
-
)
|
| 90 |
-
features = gr.Code(label="Features", language="json")
|
| 91 |
with gr.Row():
|
| 92 |
-
query = gr.Textbox(label="Query")
|
| 93 |
with gr.Row():
|
| 94 |
sql_out = gr.Code(label="SQL Query")
|
| 95 |
with gr.Row():
|
|
@@ -103,13 +100,13 @@ with gr.Blocks() as demo:
|
|
| 103 |
).then(
|
| 104 |
fn=get_column_info,
|
| 105 |
inputs=[search_in],
|
| 106 |
-
outputs=[
|
| 107 |
)
|
| 108 |
|
| 109 |
btn2.click(
|
| 110 |
fn=query_dataset,
|
| 111 |
-
inputs=[search_in,
|
| 112 |
-
outputs=[sql_out],
|
| 113 |
)
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
|
|
|
| 35 |
def get_column_info(hub_repo_id):
|
| 36 |
url: str = f"https://datasets-server.huggingface.co/info?dataset={hub_repo_id}"
|
| 37 |
response = requests.get(url)
|
| 38 |
+
try:
|
| 39 |
+
data = response.json()
|
| 40 |
+
data = data.get("dataset_info")
|
| 41 |
+
key = list(data.keys())[0]
|
| 42 |
+
features: str = json.dumps(data.get(key).get("features"))
|
| 43 |
+
except Exception as e:
|
| 44 |
+
gr.Error(f"Error getting column info: {e}")
|
| 45 |
+
return features
|
| 46 |
|
| 47 |
|
| 48 |
+
def query_dataset(hub_repo_id, features, query):
|
| 49 |
messages = [
|
| 50 |
{
|
| 51 |
"role": "system",
|
|
|
|
| 53 |
},
|
| 54 |
{
|
| 55 |
"role": "user",
|
| 56 |
+
"content": f"""table train
|
|
|
|
|
|
|
| 57 |
# Features
|
| 58 |
{features}
|
| 59 |
|
|
|
|
| 84 |
with gr.Row():
|
| 85 |
search_out = gr.HTML(label="Search Results")
|
| 86 |
with gr.Row():
|
| 87 |
+
features = gr.Code(label="Features", language="json", visible=False)
|
|
|
|
|
|
|
|
|
|
| 88 |
with gr.Row():
|
| 89 |
+
query = gr.Textbox(label="Query", placeholder="Enter a query to generate SQL")
|
| 90 |
with gr.Row():
|
| 91 |
sql_out = gr.Code(label="SQL Query")
|
| 92 |
with gr.Row():
|
|
|
|
| 100 |
).then(
|
| 101 |
fn=get_column_info,
|
| 102 |
inputs=[search_in],
|
| 103 |
+
outputs=[features],
|
| 104 |
)
|
| 105 |
|
| 106 |
btn2.click(
|
| 107 |
fn=query_dataset,
|
| 108 |
+
inputs=[search_in, features, query],
|
| 109 |
+
outputs=[sql_out, search_out],
|
| 110 |
)
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|