import gradio as gr import pandas as pd def process_csv(df): # Check for commas in any of the columns and filter out those rows df = df[~df.apply(lambda row: row.astype(str).str.contains(',').any(), axis=1)] # Split the 'title' column on ' -' and keep only the first part df['title'] = df['title'].str.split(' -').str[0] df = df.rename(columns={'request_text': 'Veta', 'intent_1': 'Intent', 'title': 'ID Odpovedi'}) # Apply a filter to eliminate rows with the 'Veta' column that have less than or equal to 3 words df = df[df['Veta'].str.split().str.len() > 3] # Delete all rows where 'Intent' contains 'Cognitive' or 'SmallTalk' df = df.dropna(subset=['Intent']) df = df[~df['Intent'].str.contains('Cognitive|SmallTalk')] # Using the pandas dataframe sample function to get 200 random rows df = df.sample(200, random_state=42, replace=True) return df def process_and_save(file): # Load the CSV file into a DataFrame df = pd.read_csv(file.name, index_col=False) df.reset_index(drop=True, inplace=True) # Process the DataFrame using your script processed_df = process_csv(df) # Save the processed DataFrame to an Excel file output_file = 'processed_output.csv' processed_df.to_csv(output_file, index=False) return output_file # Define the Gradio interface interface = gr.Interface( fn=process_and_save, inputs=gr.File(label="Upload CSV File"), outputs=gr.File(label="Download Excel File"), title="Zprocesuj denní testy pro Testing Tool", description="Načti export denních testů z PowerBI v csv a klikni na 'Submit' Pak stáhni zprocesovaný csv soubor." ) if __name__ == "__main__": interface.launch(share=True)