Spaces:
Running
Running
admin
commited on
Commit
•
f507537
1
Parent(s):
8ebf2bb
sync
Browse files- .gitattributes +11 -11
- .gitignore +4 -0
- README.md +4 -4
- app.py +81 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
|
|
11 |
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
13 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
17 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
20 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
22 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
|
|
24 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.db* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.ark* filter=lfs diff=lfs merge=lfs -text
|
30 |
+
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
31 |
+
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
32 |
+
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*.AppImage filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
example/*
|
2 |
+
*__pycache__
|
3 |
+
test.py
|
4 |
+
rename.sh
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.24.0
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
+
title: RCT Generator
|
3 |
+
emoji: 📊
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.24.0
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import csv
|
3 |
+
import random
|
4 |
+
import shutil
|
5 |
+
import pandas as pd
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
DATA_DIR = "./data"
|
9 |
+
|
10 |
+
|
11 |
+
def list_to_csv(list_of_dicts: list, filename: str):
|
12 |
+
keys = dict(list_of_dicts[0]).keys()
|
13 |
+
# 将列表中的字典写入 CSV 文件
|
14 |
+
with open(filename, "w", newline="", encoding="utf-8") as csvfile:
|
15 |
+
writer = csv.DictWriter(csvfile, fieldnames=keys)
|
16 |
+
writer.writeheader()
|
17 |
+
for data in list_of_dicts:
|
18 |
+
writer.writerow(data)
|
19 |
+
|
20 |
+
return filename
|
21 |
+
|
22 |
+
|
23 |
+
def random_allocation(participants: int, ratio: list):
|
24 |
+
total = sum(ratio)
|
25 |
+
splits = [0]
|
26 |
+
for i, r in enumerate(ratio):
|
27 |
+
splits.append(splits[i] + int(1.0 * r / total * participants))
|
28 |
+
|
29 |
+
splits[-1] = participants
|
30 |
+
partist = list(range(1, participants + 1))
|
31 |
+
random.shuffle(partist)
|
32 |
+
allocation = []
|
33 |
+
groups = len(ratio)
|
34 |
+
for i in range(groups):
|
35 |
+
start = splits[i]
|
36 |
+
end = splits[i + 1]
|
37 |
+
for participant in partist[start:end]:
|
38 |
+
allocation.append({"id": participant, "group": i + 1})
|
39 |
+
|
40 |
+
sorted_data = sorted(allocation, key=lambda x: x["id"])
|
41 |
+
filename = list_to_csv(sorted_data, f"{DATA_DIR}/output.csv")
|
42 |
+
return filename, pd.DataFrame(sorted_data)
|
43 |
+
|
44 |
+
|
45 |
+
def inference(participants: float, ratios: str):
|
46 |
+
if os.path.exists(DATA_DIR):
|
47 |
+
shutil.rmtree(DATA_DIR)
|
48 |
+
|
49 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
50 |
+
ratio_list = ratios.split(":")
|
51 |
+
ratio = []
|
52 |
+
try:
|
53 |
+
for r in ratio_list:
|
54 |
+
current_ratio = float(r.strip())
|
55 |
+
if current_ratio > 0:
|
56 |
+
ratio.append(current_ratio)
|
57 |
+
|
58 |
+
except Exception:
|
59 |
+
print("Invalid input of ratio!")
|
60 |
+
|
61 |
+
return random_allocation(int(participants), ratio)
|
62 |
+
|
63 |
+
|
64 |
+
if __name__ == "__main__":
|
65 |
+
gr.Interface(
|
66 |
+
fn=inference,
|
67 |
+
inputs=[
|
68 |
+
gr.Number(
|
69 |
+
label="输入参与者数量 (Number of participants)",
|
70 |
+
value=10,
|
71 |
+
),
|
72 |
+
gr.Textbox(label="输入分组比率 (Grouping ratio)", value="8:1:1"),
|
73 |
+
],
|
74 |
+
outputs=[
|
75 |
+
gr.components.File(label="下载随机分组数据 CSV (Download data CSV)"),
|
76 |
+
gr.Dataframe(label="随机分组数据预览 (Data preview)"),
|
77 |
+
],
|
78 |
+
title="随机对照试验随机数生成器<br>Randomized Controlled Trial Generator",
|
79 |
+
description="输入参与者数量和分组比率,格式为用:隔开的数字,生成随机分组数据。<br>Enter the number of participants and the grouping ratio in the format of numbers separated by : to generate randomized grouping data.",
|
80 |
+
allow_flagging=False,
|
81 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
librosa==0.9.2
|
2 |
+
piano_transcription_inference
|
3 |
+
pymupdf
|
4 |
+
music21
|
5 |
+
torch
|