Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ from huggingface_hub import InferenceClient
|
|
3 |
|
4 |
from datasets import load_dataset
|
5 |
|
|
|
|
|
|
|
6 |
"""
|
7 |
For more information on `huggingface_hub` Inference API support,
|
8 |
please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
@@ -69,20 +72,32 @@ def load_new_dataset():
|
|
69 |
gr.Info(message="Loading dataset...")
|
70 |
ds = load_dataset("fka/awesome-chatgpt-prompts", split="train")
|
71 |
|
72 |
-
def run_query(
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
#----------------------
|
77 |
|
78 |
with gr.Blocks() as demo:
|
79 |
-
text_input = gr.Textbox(visible=True, label="
|
80 |
btn_run = gr.Button(visible=True, value="Search")
|
81 |
results_output = gr.Dataframe(label="Results", visible=True, wrap=True)
|
82 |
logging_output = gr.Label(visible="True", value="My first logging message")
|
83 |
|
84 |
btn_run.click(
|
85 |
-
fn=
|
86 |
inputs=text_input,
|
87 |
outputs=[results_output, logging_output] # Update both the DataFrame and the label
|
88 |
)
|
|
|
3 |
|
4 |
from datasets import load_dataset
|
5 |
|
6 |
+
global ds
|
7 |
+
|
8 |
+
|
9 |
"""
|
10 |
For more information on `huggingface_hub` Inference API support,
|
11 |
please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
|
|
72 |
gr.Info(message="Loading dataset...")
|
73 |
ds = load_dataset("fka/awesome-chatgpt-prompts", split="train")
|
74 |
|
75 |
+
def run_query(input: str):
|
76 |
+
try:
|
77 |
+
df_results = duckdb.sql(
|
78 |
+
query=f"""
|
79 |
+
SELECT *
|
80 |
+
FROM ds
|
81 |
+
WHERE act LIKE '%{input}%'
|
82 |
+
"""
|
83 |
+
).to_df()
|
84 |
+
|
85 |
+
logging_message = f"Results for '{input}' found."
|
86 |
+
except Exception as e:
|
87 |
+
raise gr.Error(f"Error running query: {e}")
|
88 |
+
|
89 |
+
return df_results, logging_message
|
90 |
|
91 |
#----------------------
|
92 |
|
93 |
with gr.Blocks() as demo:
|
94 |
+
text_input = gr.Textbox(visible=True, label="Enter value for 'act':")
|
95 |
btn_run = gr.Button(visible=True, value="Search")
|
96 |
results_output = gr.Dataframe(label="Results", visible=True, wrap=True)
|
97 |
logging_output = gr.Label(visible="True", value="My first logging message")
|
98 |
|
99 |
btn_run.click(
|
100 |
+
fn=run_query, # Call the run_query function and update the label
|
101 |
inputs=text_input,
|
102 |
outputs=[results_output, logging_output] # Update both the DataFrame and the label
|
103 |
)
|