Spaces:
Running
Running
Upload 2 files
Browse files- app.py +43 -56
- constants.py +81 -0
app.py
CHANGED
@@ -1,15 +1,19 @@
|
|
1 |
import os.path
|
|
|
2 |
import gradio as gr
|
|
|
3 |
import pandas as pd
|
|
|
4 |
from constants import *
|
5 |
|
6 |
-
|
7 |
def get_download_link_model(task, dataset, example):
|
8 |
_task_path = TASK_PATH_MAPPING[task]
|
9 |
_dataset_path = DATASET_PATH_MAPPING[dataset]
|
10 |
_example_path = EXAMPLE_PATH_MAPPING[example]
|
11 |
return os.path.join("data", _task_path, _dataset_path, "weight", f"{_example_path}.zip")
|
12 |
|
|
|
13 |
def get_download_link_json(task, dataset, example):
|
14 |
_task_path = TASK_PATH_MAPPING[task]
|
15 |
_dataset_path = DATASET_PATH_MAPPING[dataset]
|
@@ -19,48 +23,48 @@ def get_download_link_json(task, dataset, example):
|
|
19 |
else:
|
20 |
return os.path.join("data", _task_path, _dataset_path, "json", f"{_example_path}.json")
|
21 |
|
22 |
-
|
23 |
def get_data(task, dataset, example):
|
24 |
_task_path = TASK_PATH_MAPPING[task]
|
25 |
_dataset_path = DATASET_PATH_MAPPING[dataset]
|
26 |
_example_path = EXAMPLE_PATH_MAPPING[example]
|
27 |
csv_file = os.path.join("data", _task_path, _dataset_path, "csv", f"{_example_path}.csv")
|
28 |
if not os.path.exists(csv_file):
|
29 |
-
return
|
30 |
-
|
31 |
read_data = pd.read_csv(csv_file)
|
32 |
data = pd.DataFrame(columns=COLUMN_NAMES)
|
33 |
-
average_acc = None
|
34 |
|
35 |
if _task_path == "coding":
|
36 |
-
for
|
37 |
-
data =
|
38 |
"Prompt": row["prompt"],
|
39 |
"Pass@1": round(float(row["pass@1"]) * 100, 3),
|
40 |
"Pass@5": round(float(row["pass@5"]) * 100, 3),
|
41 |
"Pass@10": round(float(row["pass@10"]) * 100, 3),
|
42 |
"Correctness": "N/A"
|
43 |
-
}
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
53 |
"Prompt": row["prompt"],
|
54 |
"Pass@1": None,
|
55 |
"Pass@5": None,
|
56 |
"Pass@10": None,
|
57 |
"Correctness": "✅" if row["correctness"] else "❌"
|
58 |
-
}
|
59 |
-
|
|
|
60 |
|
61 |
-
return data, average_acc
|
62 |
|
63 |
-
# ------------ Gradio UI ------------
|
64 |
with gr.Blocks() as demo_board:
|
65 |
gr.HTML(DND_HEADER)
|
66 |
gr.Markdown(DND_INTRODUCTION)
|
@@ -84,20 +88,8 @@ with gr.Blocks() as demo_board:
|
|
84 |
interactive=True,
|
85 |
)
|
86 |
|
87 |
-
# 平均准确率(放在 Prompt 表格上方)
|
88 |
-
average_acc_display = gr.Textbox(
|
89 |
-
label="Average Accuracy (%)",
|
90 |
-
value=lambda: str(get_data(task.value, dataset.value, example.value)[1]),
|
91 |
-
interactive=False,
|
92 |
-
visible=True,
|
93 |
-
scale=0,
|
94 |
-
max_lines=1,
|
95 |
-
min_width=160
|
96 |
-
)
|
97 |
-
|
98 |
-
# Prompt 表格
|
99 |
board = gr.components.Dataframe(
|
100 |
-
value=
|
101 |
column_widths=["60%", "10%", "10%", "10%", "10%"],
|
102 |
headers=COLUMN_NAMES,
|
103 |
type="pandas",
|
@@ -107,31 +99,28 @@ with gr.Blocks() as demo_board:
|
|
107 |
max_height=500,
|
108 |
)
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
interactive=True,
|
117 |
-
),
|
118 |
-
inputs=[task],
|
119 |
-
outputs=dataset
|
120 |
-
)
|
121 |
|
122 |
-
# 联动更新:task / dataset / example -> 表格 + 平均准确率
|
123 |
for component in [task, dataset, example]:
|
124 |
-
component.change(
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
# 下载按钮
|
131 |
with gr.Row():
|
132 |
json_downloader = gr.DownloadButton("Download JSON", visible=True)
|
133 |
model_downloader = gr.DownloadButton("Download Model", visible=True)
|
134 |
-
|
135 |
json_downloader.click(
|
136 |
fn=get_download_link_json,
|
137 |
inputs=[task, dataset, example],
|
@@ -143,7 +132,6 @@ with gr.Blocks() as demo_board:
|
|
143 |
outputs=model_downloader,
|
144 |
)
|
145 |
|
146 |
-
# 引用文本
|
147 |
citation_button = gr.Textbox(
|
148 |
value=CITATION_BUTTON_TEXT,
|
149 |
label=CITATION_BUTTON_LABEL,
|
@@ -152,5 +140,4 @@ with gr.Blocks() as demo_board:
|
|
152 |
show_copy_button=True,
|
153 |
)
|
154 |
|
155 |
-
|
156 |
-
demo_board.launch()
|
|
|
1 |
import os.path
|
2 |
+
|
3 |
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
import pandas as pd
|
6 |
+
|
7 |
from constants import *
|
8 |
|
9 |
+
|
10 |
def get_download_link_model(task, dataset, example):
|
11 |
_task_path = TASK_PATH_MAPPING[task]
|
12 |
_dataset_path = DATASET_PATH_MAPPING[dataset]
|
13 |
_example_path = EXAMPLE_PATH_MAPPING[example]
|
14 |
return os.path.join("data", _task_path, _dataset_path, "weight", f"{_example_path}.zip")
|
15 |
|
16 |
+
|
17 |
def get_download_link_json(task, dataset, example):
|
18 |
_task_path = TASK_PATH_MAPPING[task]
|
19 |
_dataset_path = DATASET_PATH_MAPPING[dataset]
|
|
|
23 |
else:
|
24 |
return os.path.join("data", _task_path, _dataset_path, "json", f"{_example_path}.json")
|
25 |
|
26 |
+
|
27 |
def get_data(task, dataset, example):
|
28 |
_task_path = TASK_PATH_MAPPING[task]
|
29 |
_dataset_path = DATASET_PATH_MAPPING[dataset]
|
30 |
_example_path = EXAMPLE_PATH_MAPPING[example]
|
31 |
csv_file = os.path.join("data", _task_path, _dataset_path, "csv", f"{_example_path}.csv")
|
32 |
if not os.path.exists(csv_file):
|
33 |
+
return
|
|
|
34 |
read_data = pd.read_csv(csv_file)
|
35 |
data = pd.DataFrame(columns=COLUMN_NAMES)
|
|
|
36 |
|
37 |
if _task_path == "coding":
|
38 |
+
for index, row in read_data.iterrows():
|
39 |
+
data = data._append({
|
40 |
"Prompt": row["prompt"],
|
41 |
"Pass@1": round(float(row["pass@1"]) * 100, 3),
|
42 |
"Pass@5": round(float(row["pass@5"]) * 100, 3),
|
43 |
"Pass@10": round(float(row["pass@10"]) * 100, 3),
|
44 |
"Correctness": "N/A"
|
45 |
+
}, ignore_index=True)
|
46 |
+
elif _task_path == "common":
|
47 |
+
for index, row in read_data.iterrows():
|
48 |
+
data = data._append({
|
49 |
+
"Prompt": row["prompt"],
|
50 |
+
"Pass@1": None,
|
51 |
+
"Pass@5": None,
|
52 |
+
"Pass@10": None,
|
53 |
+
"Correctness": "✅" if row["correctness"] else "❌"
|
54 |
+
}, ignore_index=True)
|
55 |
+
elif _task_path == "math":
|
56 |
+
for index, row in read_data.iterrows():
|
57 |
+
data = data._append({
|
58 |
"Prompt": row["prompt"],
|
59 |
"Pass@1": None,
|
60 |
"Pass@5": None,
|
61 |
"Pass@10": None,
|
62 |
"Correctness": "✅" if row["correctness"] else "❌"
|
63 |
+
}, ignore_index=True)
|
64 |
+
|
65 |
+
return data
|
66 |
|
|
|
67 |
|
|
|
68 |
with gr.Blocks() as demo_board:
|
69 |
gr.HTML(DND_HEADER)
|
70 |
gr.Markdown(DND_INTRODUCTION)
|
|
|
88 |
interactive=True,
|
89 |
)
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
board = gr.components.Dataframe(
|
92 |
+
value=get_data(task.value, dataset.value, example.value),
|
93 |
column_widths=["60%", "10%", "10%", "10%", "10%"],
|
94 |
headers=COLUMN_NAMES,
|
95 |
type="pandas",
|
|
|
99 |
max_height=500,
|
100 |
)
|
101 |
|
102 |
+
task.change(lambda t: gr.Radio(
|
103 |
+
label="Dataset",
|
104 |
+
choices=TASK_DATASET_LIST[t],
|
105 |
+
value=TASK_DATASET_LIST[t][0],
|
106 |
+
interactive=True,
|
107 |
+
), inputs=[task], outputs=dataset)
|
|
|
|
|
|
|
|
|
|
|
108 |
|
|
|
109 |
for component in [task, dataset, example]:
|
110 |
+
component.change(lambda t, d, e: gr.components.Dataframe(
|
111 |
+
value=get_data(t, d, e),
|
112 |
+
column_widths=["60%", "10%", "10%", "10%", "10%"],
|
113 |
+
headers=COLUMN_NAMES,
|
114 |
+
type="pandas",
|
115 |
+
datatype=DATA_TITLE_TYPE,
|
116 |
+
interactive=False,
|
117 |
+
visible=True,
|
118 |
+
max_height=500,
|
119 |
+
), inputs=[task, dataset, example], outputs=board)
|
120 |
|
|
|
121 |
with gr.Row():
|
122 |
json_downloader = gr.DownloadButton("Download JSON", visible=True)
|
123 |
model_downloader = gr.DownloadButton("Download Model", visible=True)
|
|
|
124 |
json_downloader.click(
|
125 |
fn=get_download_link_json,
|
126 |
inputs=[task, dataset, example],
|
|
|
132 |
outputs=model_downloader,
|
133 |
)
|
134 |
|
|
|
135 |
citation_button = gr.Textbox(
|
136 |
value=CITATION_BUTTON_TEXT,
|
137 |
label=CITATION_BUTTON_LABEL,
|
|
|
140 |
show_copy_button=True,
|
141 |
)
|
142 |
|
143 |
+
demo_board.launch()
|
|
constants.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
DND_HEADER = """
|
2 |
+
<style>
|
3 |
+
.header-gradient {
|
4 |
+
top: 40%;
|
5 |
+
bottom: 40%;
|
6 |
+
padding: 10px 0px;
|
7 |
+
font-weight: bold;
|
8 |
+
font-size: 40px;
|
9 |
+
font-family: Inter, Arial, Helvetica, sans-serif;
|
10 |
+
background: linear-gradient(to right, #67a102, #c0dc90);
|
11 |
+
-webkit-text-fill-color: transparent;
|
12 |
+
-webkit-background-clip: text;
|
13 |
+
}
|
14 |
+
|
15 |
+
.header-normal {
|
16 |
+
top: 40%;
|
17 |
+
bottom: 40%;
|
18 |
+
padding: 10px 0px;
|
19 |
+
font-weight: bold;
|
20 |
+
font-size: 40px;
|
21 |
+
font-family: Inter, Arial, Helvetica, sans-serif;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
|
25 |
+
<div align="center">
|
26 |
+
<span class="header-gradient"> Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights </span>
|
27 |
+
</div>
|
28 |
+
<p align="center">
|
29 |
+
| <a href=""><b>Documentation</b></a> | <a href=""><b>Github</b></a> | <a href="https://arxiv.org/abs/2506.16406"><b>Paper </b> </a> | <a href="https://x.com/VictorKaiWang1/status/1935905121659240513"><b>Twitter/X</b> </a> |
|
30 |
+
</p>"""
|
31 |
+
|
32 |
+
DND_INTRODUCTION = """
|
33 |
+
🚀 Welcome to the Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights!
|
34 |
+
|
35 |
+
> Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights is a zero-shot prompt-to-weights model that can generate a model from a prompt.
|
36 |
+
|
37 |
+
- **Zero-Shot**: Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights can generate a model from a prompt without any training data.
|
38 |
+
- **Prompt-to-Weights**: Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights can generate a model from a prompt.
|
39 |
+
- **Easy-to-use**: Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights provides a unified interface for prompt-to-weights model generation.
|
40 |
+
|
41 |
+
"""
|
42 |
+
|
43 |
+
TASK_LIST = ["🧠 Commonsense Reasoning", "🔢 Math", "💻 Coding"]
|
44 |
+
TASK_DATASET_LIST = {
|
45 |
+
"🧠 Commonsense Reasoning": ["ARC-c", "OBQA"],
|
46 |
+
"🔢 Math": ["GSM-8K"],
|
47 |
+
"💻 Coding": ["HumanEval"],
|
48 |
+
}
|
49 |
+
EXAMPLE_LIST = ["Example 1", "Example 2", "Example 3", "Example 4", "Example 5"]
|
50 |
+
|
51 |
+
TASK_PATH_MAPPING = {
|
52 |
+
"🧠 Commonsense Reasoning": "common",
|
53 |
+
"🔢 Math": "math",
|
54 |
+
"💻 Coding": "coding",
|
55 |
+
}
|
56 |
+
DATASET_PATH_MAPPING = {
|
57 |
+
"ARC-c": "arc_c",
|
58 |
+
"OBQA": "obqa",
|
59 |
+
"GSM-8K": "gsm8k",
|
60 |
+
"HumanEval": "humaneval",
|
61 |
+
}
|
62 |
+
EXAMPLE_PATH_MAPPING = {
|
63 |
+
"Example 1": "1",
|
64 |
+
"Example 2": "2",
|
65 |
+
"Example 3": "3",
|
66 |
+
"Example 4": "4",
|
67 |
+
"Example 5": "5",
|
68 |
+
}
|
69 |
+
|
70 |
+
COLUMN_NAMES = ["Prompt", "Pass@1", "Pass@5", "Pass@10", "Correctness"]
|
71 |
+
DATA_TITLE_TYPE = ['markdown', 'number', 'number', 'number', 'markdown']
|
72 |
+
|
73 |
+
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
|
74 |
+
CITATION_BUTTON_TEXT = r"""
|
75 |
+
@article{liang2025drag,
|
76 |
+
title={Drag-and-Drop LLMs: Zero-Shot Prompt-to-Weights},
|
77 |
+
author={Liang, Zhiyuan and Tang, Dongwen and Zhou, Yuhao and Zhao, Xuanlei and Shi, Mingjia and Zhao, Wangbo and Li, Zekai and Wang, Peihao and Sch{\"u}rholt, Konstantin and Borth, Damian and others},
|
78 |
+
journal={arXiv preprint arXiv:2506.16406},
|
79 |
+
year={2025}
|
80 |
+
}
|
81 |
+
"""
|