Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +42 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def process_csv(df):
|
| 6 |
+
# Split the 'title' column on ' -' and keep only the first part
|
| 7 |
+
df['title'] = df['title'].str.split(' -').str[0]
|
| 8 |
+
df = df.rename(columns={'request_text': 'Veta', 'intent_1': 'Intent', 'title': 'ID Odpovedi'})
|
| 9 |
+
# Apply a filter to eliminate rows with the 'Veta' column that have less than or equal to 3 words
|
| 10 |
+
df = df[df['Veta'].str.split().str.len() > 3]
|
| 11 |
+
# Delete all rows where 'Intent' contains 'Cognitive' or 'SmallTalk'
|
| 12 |
+
df = df[~df['Intent'].str.contains('Cognitive|SmallTalk')]
|
| 13 |
+
# Using the pandas dataframe sample function to get 200 random rows
|
| 14 |
+
df = df.sample(200, random_state=42)
|
| 15 |
+
return df
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def process_and_save(file):
|
| 19 |
+
# Load the CSV file into a DataFrame
|
| 20 |
+
df = pd.read_csv(file.name)
|
| 21 |
+
|
| 22 |
+
# Process the DataFrame using your script
|
| 23 |
+
processed_df = process_csv(df)
|
| 24 |
+
|
| 25 |
+
# Save the processed DataFrame to an Excel file
|
| 26 |
+
output_file = 'processed_output.csv'
|
| 27 |
+
processed_df.to_csv(output_file, index=False)
|
| 28 |
+
|
| 29 |
+
return output_file
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# Define the Gradio interface
|
| 33 |
+
interface = gr.Interface(
|
| 34 |
+
fn=process_and_save,
|
| 35 |
+
inputs=gr.File(label="Upload CSV File"),
|
| 36 |
+
outputs=gr.File(label="Download Excel File"),
|
| 37 |
+
title="Zprocesuj denní testy pro Testing Tool",
|
| 38 |
+
description="Načti export denních testů z PowerBI v csv a klikni na 'Submit' Pak stáhni zprocesovaný csv soubor."
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
interface.launch(share=True)
|
requirements.txt
ADDED
|
Binary file (4.85 kB). View file
|
|
|