Spaces:
Sleeping
Sleeping
augray
commited on
Commit
•
2ebc3cc
1
Parent(s):
a46b4c4
configurable config/split
Browse files
app.py
CHANGED
@@ -72,14 +72,12 @@ def get_table_name(config: str | None, split: str | None, config_choices: list[s
|
|
72 |
return table_name.lower()
|
73 |
|
74 |
|
75 |
-
def get_prompt_messages(card_data: dict[str, Any], natural_language_query: str):
|
76 |
config_choices = get_config_choices(card_data)
|
77 |
split_choices = get_split_choices(card_data)
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
table_name = get_table_name(chosen_config, chosen_split, config_choices, split_choices)
|
82 |
-
features = card_data[chosen_config]["features"]
|
83 |
messages = [
|
84 |
{
|
85 |
"role": "system",
|
@@ -111,9 +109,9 @@ def get_split_choices(card_data: dict[str, Any]) -> list[str]:
|
|
111 |
return list(splits)
|
112 |
|
113 |
|
114 |
-
def query_dataset(hub_repo_id, card_data, query):
|
115 |
card_data = json.loads(card_data)
|
116 |
-
messages = get_prompt_messages(card_data, query)
|
117 |
api_key = os.environ["API_KEY_TOGETHER_AI"].strip()
|
118 |
response = requests.post(
|
119 |
"https://api.together.xyz/v1/chat/completions",
|
@@ -180,9 +178,27 @@ with gr.Blocks() as demo:
|
|
180 |
lines=1,
|
181 |
visible=False,
|
182 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
-
@gr.render(triggers=[search_in.submit])
|
185 |
-
def show_config_split_choices():
|
186 |
with gr.Row():
|
187 |
with gr.Column():
|
188 |
btn = gr.Button("Show Dataset")
|
@@ -190,8 +206,6 @@ with gr.Blocks() as demo:
|
|
190 |
btn2 = gr.Button("Query Dataset")
|
191 |
with gr.Row():
|
192 |
search_out = gr.HTML(label="Search Results")
|
193 |
-
with gr.Row():
|
194 |
-
card_data = gr.Code(label="Card data", language="json", visible=False)
|
195 |
gr.on(
|
196 |
[btn.click, search_in.submit],
|
197 |
fn=get_iframe,
|
@@ -205,7 +219,7 @@ with gr.Blocks() as demo:
|
|
205 |
gr.on(
|
206 |
[btn2.click, query.submit],
|
207 |
fn=query_dataset,
|
208 |
-
inputs=[search_in, card_data, query],
|
209 |
outputs=[sql_out, search_out],
|
210 |
)
|
211 |
|
|
|
72 |
return table_name.lower()
|
73 |
|
74 |
|
75 |
+
def get_prompt_messages(card_data: dict[str, Any], natural_language_query: str, config: str | None, split: str | None):
|
76 |
config_choices = get_config_choices(card_data)
|
77 |
split_choices = get_split_choices(card_data)
|
78 |
|
79 |
+
table_name = get_table_name(config, split, config_choices, split_choices)
|
80 |
+
features = card_data[config]["features"]
|
|
|
|
|
81 |
messages = [
|
82 |
{
|
83 |
"role": "system",
|
|
|
109 |
return list(splits)
|
110 |
|
111 |
|
112 |
+
def query_dataset(hub_repo_id, card_data, query, config, split):
|
113 |
card_data = json.loads(card_data)
|
114 |
+
messages = get_prompt_messages(card_data, query, config, split)
|
115 |
api_key = os.environ["API_KEY_TOGETHER_AI"].strip()
|
116 |
response = requests.post(
|
117 |
"https://api.together.xyz/v1/chat/completions",
|
|
|
178 |
lines=1,
|
179 |
visible=False,
|
180 |
)
|
181 |
+
with gr.Row():
|
182 |
+
card_data = gr.Code(label="Card data", language="json", visible=False)
|
183 |
+
|
184 |
+
@gr.render(inputs=[card_data])
|
185 |
+
def show_config_split_choices(data):
|
186 |
+
try:
|
187 |
+
data = json.loads(data.strip())
|
188 |
+
config_choices = get_config_choices(data)
|
189 |
+
split_choices = get_split_choices(data)
|
190 |
+
except Exception:
|
191 |
+
config_choices = []
|
192 |
+
split_choices = []
|
193 |
+
|
194 |
+
initial_config = config_choices[0] if len(config_choices) > 0 else None
|
195 |
+
initial_split = split_choices[0] if len(split_choices) > 0 else None
|
196 |
+
with gr.Row():
|
197 |
+
with gr.Column():
|
198 |
+
config_selection = gr.Dropdown(label="Config Name", choices=config_choices, value=initial_config)
|
199 |
+
with gr.Column():
|
200 |
+
split_selection = gr.Dropdown(label="Split Name", choices=split_choices, value=initial_split)
|
201 |
|
|
|
|
|
202 |
with gr.Row():
|
203 |
with gr.Column():
|
204 |
btn = gr.Button("Show Dataset")
|
|
|
206 |
btn2 = gr.Button("Query Dataset")
|
207 |
with gr.Row():
|
208 |
search_out = gr.HTML(label="Search Results")
|
|
|
|
|
209 |
gr.on(
|
210 |
[btn.click, search_in.submit],
|
211 |
fn=get_iframe,
|
|
|
219 |
gr.on(
|
220 |
[btn2.click, query.submit],
|
221 |
fn=query_dataset,
|
222 |
+
inputs=[search_in, card_data, query, config_selection, split_selection],
|
223 |
outputs=[sql_out, search_out],
|
224 |
)
|
225 |
|