File size: 1,740 Bytes
6364399 b006c18 b273bd6 6364399 67b696f 6364399 6312d90 6364399 b273bd6 6364399 aa302c7 6364399 | 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 44 45 46 47 | 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)
|