Spaces:
Sleeping
Sleeping
import pandas as pd | |
import gradio as gr | |
def filter_data(query: str, df: pd.DataFrame) -> pd.DataFrame: | |
if query: | |
return df[ | |
df.apply( | |
lambda row: row.astype(str).str.contains(query, case=False).any(), | |
axis=1 | |
) | |
] | |
else: | |
return df | |
def main(): | |
df = pd.read_csv('results.csv') | |
def update_output(query: str) -> pd.DataFrame: | |
return filter_data(query, df) | |
with gr.Blocks() as blocks: | |
query = gr.Textbox(label='Search') | |
output_df = gr.Dataframe(df) | |
query.change(fn=update_output, inputs=[query], outputs=[output_df]) | |
blocks.launch() | |
if __name__ == '__main__': | |
main() | |