File size: 1,186 Bytes
ceef207
 
 
24ac06a
8af569d
24ac06a
5901268
 
 
24ac06a
49984ff
8af569d
ceef207
5901268
 
8af569d
5901268
 
 
 
 
 
057ae12
16d482d
 
 
5901268
3458f7f
98ed10b
057ae12
 
3458f7f
5901268
057ae12
 
3458f7f
16d482d
 
 
ceef207
24ac06a
8659e00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from huggingface_hub import InferenceClient

from datasets import load_dataset
import pandas

global ds


def load_new_dataset():
    gr.Info(message="Loading dataset...")
    df = pd.read_csv("hf://datasets/fka/awesome-chatgpt-prompts/prompts.csv")

def run_query(input: str):
    try:
        df_results = df[df['act'] == input]

        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()