zealous79A's picture
Update app.py
b44dd23 verified
raw
history blame
1.31 kB
import gradio as gr
from huggingface_hub import InferenceClient
from datasets import load_dataset
import duckdb
global ds
def load_new_dataset():
gr.Info(message="Loading dataset...")
ds = load_dataset("fka/awesome-chatgpt-prompts", split="train")
def run_query(input: str):
try:
df_results = duckdb.sql(
query=f"""
SELECT *
FROM train
WHERE act LIKE '%{input}%'
"""
).to_df()
logging_message = f"Results for '{input}' found."
except Exception as e:
raise gr.Error(f"Error running query: {e}")
return df_results, logging_message
#----------------------
with gr.Blocks() as demo:
text_input = gr.Textbox(visible=True, label="Enter value for 'act':")
btn_run = gr.Button(visible=True, value="Search")
results_output = gr.Dataframe(label="Results", visible=True, wrap=True)
logging_output = gr.Label(visible="True", value="My first logging message")
btn_run.click(
fn=run_query, # Call the run_query function and update the label
inputs=text_input,
outputs=[results_output, logging_output] # Update both the DataFrame and the label
)
#----------------------
if __name__ == "__main__":
load_new_dataset()
demo.launch()