Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import random
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def group_names(file, members_per_group):
|
| 7 |
+
# Read the CSV file
|
| 8 |
+
df = pd.read_csv(file.name)
|
| 9 |
+
|
| 10 |
+
# Shuffle the DataFrame
|
| 11 |
+
df = df.sample(frac=1).reset_index(drop=True)
|
| 12 |
+
|
| 13 |
+
# Grouping
|
| 14 |
+
groups = []
|
| 15 |
+
for i in range(0, len(df), members_per_group):
|
| 16 |
+
groups.append(df[i:i + members_per_group])
|
| 17 |
+
|
| 18 |
+
# Creating a new DataFrame for grouped data
|
| 19 |
+
grouped_df = pd.DataFrame({'Group': [f'Group {i+1}' for i, group in enumerate(groups)],
|
| 20 |
+
'Names': [', '.join(group['Names'].tolist()) for group in groups]})
|
| 21 |
+
|
| 22 |
+
return grouped_df
|
| 23 |
+
|
| 24 |
+
def main_interface(file, members_per_group):
|
| 25 |
+
grouped_df = group_names(file, members_per_group)
|
| 26 |
+
# Save the DataFrame to a CSV file
|
| 27 |
+
output_filename = '/tmp/grouped_names.csv'
|
| 28 |
+
grouped_df.to_csv(output_filename, index=False)
|
| 29 |
+
return output_filename
|
| 30 |
+
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=main_interface,
|
| 33 |
+
inputs=[gr.File(label="Upload CSV File"), gr.Number(label="Members per Group", value=5)],
|
| 34 |
+
outputs=gr.File(label="Download Grouped Names CSV"),
|
| 35 |
+
allow_flagging="never"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
iface.launch()
|