gradio-checkboxgroupmarkdown 0.0.2__tar.gz → 0.0.4__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/PKG-INFO +199 -138
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/README.md +198 -137
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/checkboxgroupmarkdown.py +3 -1
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/checkboxgroupmarkdown.pyi +2 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/templates/component/index.js +5405 -4728
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/templates/component/style.css +1 -1
- gradio_checkboxgroupmarkdown-0.0.4/demo/app.py +211 -0
- gradio_checkboxgroupmarkdown-0.0.2/demo/app.py → gradio_checkboxgroupmarkdown-0.0.4/demo/old_origin_demo_app.py +1 -1
- gradio_checkboxgroupmarkdown-0.0.4/demo/space.py +334 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/frontend/Index.svelte +48 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/frontend/package-lock.json +890 -33
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/frontend/package.json +1 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/pyproject.toml +1 -1
- gradio_checkboxgroupmarkdown-0.0.2/demo/space.py +0 -286
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/.gitignore +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/__init__.py +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/templates/example/index.js +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/backend/gradio_checkboxgroupmarkdown/templates/example/style.css +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/demo/__init__.py +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/demo/css.css +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/demo/requirements.txt +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/frontend/Example.svelte +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/frontend/gradio.config.js +0 -0
- {gradio_checkboxgroupmarkdown-0.0.2 → gradio_checkboxgroupmarkdown-0.0.4}/frontend/tsconfig.json +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gradio_checkboxgroupmarkdown
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.4
|
4
4
|
Summary: Gradio component for CheckboxGroup with Markdown
|
5
5
|
Author-email: YOUR NAME <YOUREMAIL@domain.com>
|
6
6
|
License-Expression: Apache-2.0
|
@@ -48,168 +48,216 @@ pip install gradio_checkboxgroupmarkdown
|
|
48
48
|
## Usage
|
49
49
|
|
50
50
|
```python
|
51
|
-
|
52
|
-
import gradio as gr
|
53
|
-
|
54
|
-
|
55
|
-
from typing import List
|
56
51
|
import gradio as gr
|
57
|
-
from dataclasses import dataclass
|
58
52
|
import random
|
53
|
+
from typing import List, Dict
|
59
54
|
from gradio_checkboxgroupmarkdown import CheckboxGroupMarkdown
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
"
|
72
|
-
|
73
|
-
"
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
56
|
+
def generate_test_articles():
|
57
|
+
topics = ["Machine Learning", "Deep Learning", "Neural Networks", "Computer Vision",
|
58
|
+
"Natural Language Processing"]
|
59
|
+
|
60
|
+
subtopics = ["Introduction", "Tutorial", "Case Study"]
|
61
|
+
|
62
|
+
articles = []
|
63
|
+
for i in range(10):
|
64
|
+
topic = random.choice(topics)
|
65
|
+
subtopic = random.choice(subtopics)
|
66
|
+
article_id = f"art_{i+1:02d}"
|
67
|
+
|
68
|
+
title = f"{topic}: {subtopic}"
|
69
|
+
content = f"""# {title}
|
70
|
+
This article covers {topic.lower()} {subtopic.lower()}.
|
71
|
+
Key points:
|
72
|
+
- Basic concepts
|
73
|
+
- Implementation tips
|
74
|
+
- Practical examples"""
|
75
|
+
|
76
|
+
articles.append({
|
77
|
+
"id": article_id,
|
78
|
+
"title": title,
|
79
|
+
"content": content,
|
80
|
+
"selected": False
|
81
|
+
})
|
82
|
+
|
83
|
+
return articles
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
"
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
"content": "# Feature Engineering\nMaster the art of creating meaningful features from raw data.",
|
100
|
-
"selected": False
|
101
|
-
}
|
102
|
-
]
|
85
|
+
def search_articles(search_text: str, master_articles: List[Dict]) -> List[Dict]:
|
86
|
+
print("search_articles")
|
87
|
+
|
88
|
+
"""Search articles based on input text"""
|
89
|
+
if not search_text.strip():
|
90
|
+
return master_articles
|
91
|
+
|
92
|
+
search_terms = search_text.lower().split()
|
93
|
+
filtered_articles = []
|
94
|
+
|
95
|
+
for article in master_articles:
|
96
|
+
text_to_search = (article["title"] + " " + article["content"]).lower()
|
97
|
+
if all(term in text_to_search for term in search_terms):
|
98
|
+
filtered_articles.append(article)
|
99
|
+
|
100
|
+
return filtered_articles
|
103
101
|
|
104
|
-
|
105
|
-
|
106
|
-
# return "You haven't selected any articles yet."
|
102
|
+
def update_filtered_articles(search_text: str, master_articles: List[Dict]):
|
103
|
+
print("update_filtered_articles")
|
107
104
|
|
108
|
-
|
109
|
-
|
110
|
-
# for choice in selected:
|
111
|
-
# formatted_choices.append(
|
112
|
-
# f"ID: {choice['id']}\nTitle: {choice['title']}\nContent: {choice['content']}"
|
113
|
-
# )
|
114
|
-
# return "Selected articles are:\n\n" + "\n\n".join(formatted_choices)
|
115
|
-
# else:
|
116
|
-
# return "Selected articles are:\n\n- " + "\n- ".join(selected)
|
117
|
-
|
118
|
-
def sentence_builder(selected):
|
119
|
-
print("\nIn sentence_builder:")
|
120
|
-
print("Selected items:", selected)
|
105
|
+
"""Update the first CheckboxGroupMarkdown with filtered articles"""
|
106
|
+
filtered = search_articles(search_text, master_articles)
|
121
107
|
|
122
|
-
|
123
|
-
|
108
|
+
return {
|
109
|
+
filtered_checkbox: gr.update(
|
110
|
+
choices=filtered,
|
111
|
+
value=[art["id"] for art in filtered if art["selected"]]
|
112
|
+
),
|
113
|
+
filtered_checkbox_state: filtered
|
114
|
+
}
|
124
115
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
116
|
+
def update_selected_checkbox_articles(selected_choices, filtered_checkbox, master_articles: List[Dict]):
|
117
|
+
print("handle_deselect_articles")
|
118
|
+
|
119
|
+
"""Update master articles by removing unselected ones"""
|
120
|
+
# Get IDs of articles that remain selected
|
121
|
+
selected_ids = {choice["id"] for choice in selected_choices}
|
122
|
+
|
123
|
+
# Update selection status in master_articles
|
124
|
+
for article in master_articles:
|
125
|
+
article["selected"] = article["id"] in selected_ids
|
126
|
+
|
127
|
+
# Update selection status in filtered_checkbox
|
128
|
+
for article in filtered_checkbox:
|
129
|
+
article["selected"] = article["id"] in selected_ids
|
130
|
+
|
131
|
+
# Get selected articles for second tab
|
132
|
+
selected_articles = [
|
133
|
+
{
|
134
|
+
"id": art["id"],
|
135
|
+
"title": art["title"],
|
136
|
+
"content": art["content"],
|
137
|
+
"selected": True
|
138
|
+
}
|
139
|
+
for art in master_articles
|
140
|
+
if art["selected"]
|
141
|
+
]
|
142
|
+
|
143
|
+
return [
|
144
|
+
gr.update(
|
145
|
+
choices=selected_articles,
|
146
|
+
value=[art["id"] for art in selected_articles]
|
147
|
+
),
|
148
|
+
gr.update(
|
149
|
+
value=[art["id"] for art in filtered_checkbox if art["selected"]]
|
150
|
+
),
|
151
|
+
master_articles,
|
152
|
+
filtered_checkbox
|
153
|
+
]
|
154
|
+
|
155
|
+
def update_filtered_checkbox_articles(selected_choices, filtered_checkbox, master_articles: List[Dict]):
|
156
|
+
print("update_selected_articles")
|
157
|
+
|
158
|
+
"""Update the second CheckboxGroupMarkdown when selections change in the first one"""
|
159
|
+
# Get IDs of newly selected articles
|
160
|
+
selected_ids = {choice["id"] for choice in selected_choices}
|
161
|
+
|
162
|
+
# Update selection status in filtered_checkbox_state
|
163
|
+
for article in filtered_checkbox:
|
164
|
+
if article["id"] in selected_ids:
|
165
|
+
article["selected"] = True
|
166
|
+
else:
|
167
|
+
article["selected"] = False
|
168
|
+
|
169
|
+
# Update selection status in master_articles based on filtered_checkbox
|
170
|
+
filtered_articles_dict = {art["id"]: art["selected"] for art in filtered_checkbox}
|
171
|
+
for article in master_articles:
|
172
|
+
if article["id"] in filtered_articles_dict:
|
173
|
+
article["selected"] = filtered_articles_dict[article["id"]]
|
174
|
+
|
175
|
+
# Get all selected articles for the second component
|
176
|
+
selected_articles = [
|
177
|
+
{
|
178
|
+
"id": art["id"],
|
179
|
+
"title": art["title"],
|
180
|
+
"content": art["content"],
|
181
|
+
"selected": True
|
182
|
+
}
|
183
|
+
for art in master_articles
|
184
|
+
if art["selected"]
|
185
|
+
]
|
186
|
+
|
187
|
+
return {
|
188
|
+
selected_checkbox: gr.update(
|
189
|
+
choices=selected_articles,
|
190
|
+
value=[art["id"] for art in selected_articles]
|
191
|
+
),
|
192
|
+
filtered_checkbox_state: filtered_checkbox,
|
193
|
+
master_articles_state: master_articles
|
194
|
+
}
|
156
195
|
|
196
|
+
# Create the Gradio interface
|
157
197
|
with gr.Blocks() as demo:
|
158
|
-
gr.Markdown("##
|
198
|
+
gr.Markdown("## Article Search and Selection Demo")
|
159
199
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
ai_btn = gr.Button("AI Articles", variant="primary")
|
165
|
-
ml_btn = gr.Button("ML Articles", variant="secondary")
|
166
|
-
mix_btn = gr.Button("Random Mix", variant="secondary")
|
200
|
+
# Create state to hold master articles list
|
201
|
+
master_articles_state = gr.State(generate_test_articles())
|
202
|
+
filtered_checkbox_state = gr.State(master_articles_state.value)
|
203
|
+
print("generate articles")
|
167
204
|
|
205
|
+
# Search bar
|
168
206
|
with gr.Row():
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
207
|
+
search_input = gr.Textbox(
|
208
|
+
label="Search Articles",
|
209
|
+
placeholder="Enter search terms...",
|
210
|
+
show_label=True
|
211
|
+
)
|
212
|
+
search_button = gr.Button("Search")
|
213
|
+
|
214
|
+
# Tabs for the two CheckboxGroupMarkdown components
|
215
|
+
with gr.Tabs() as tabs:
|
216
|
+
with gr.Tab("Search Results"):
|
217
|
+
filtered_checkbox = CheckboxGroupMarkdown(
|
218
|
+
choices=master_articles_state.value,
|
219
|
+
label="Available Articles",
|
220
|
+
info="Select articles to add to your collection",
|
174
221
|
type="all",
|
175
|
-
|
222
|
+
value=[art["id"] for art in master_articles_state.value if art["selected"]],
|
223
|
+
buttons=["select_all", "deselect_all"]
|
176
224
|
)
|
225
|
+
print("filtered_checkbox")
|
177
226
|
|
178
|
-
with gr.
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
info="
|
183
|
-
|
227
|
+
with gr.Tab("Selected Collection"):
|
228
|
+
selected_checkbox = CheckboxGroupMarkdown(
|
229
|
+
choices=[art for art in master_articles_state.value if art["selected"]],
|
230
|
+
label="Your Selected Articles",
|
231
|
+
info="Your curated collection of articles",
|
232
|
+
type="all",
|
233
|
+
value=[art["id"] for art in master_articles_state.value if art["selected"]],
|
234
|
+
buttons=["select_all", "deselect_all"]
|
184
235
|
)
|
236
|
+
print("selected_checkbox")
|
185
237
|
|
186
238
|
# Event handlers
|
187
|
-
|
188
|
-
fn=
|
189
|
-
inputs=
|
190
|
-
outputs=
|
239
|
+
search_button.click(
|
240
|
+
fn=update_filtered_articles,
|
241
|
+
inputs=[search_input, master_articles_state],
|
242
|
+
# outputs=[filtered_checkbox, master_articles_state]
|
243
|
+
outputs=[filtered_checkbox, filtered_checkbox_state]
|
191
244
|
)
|
192
245
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
outputs=[checkbox_group, output_text],
|
198
|
-
)
|
199
|
-
|
200
|
-
ml_btn.click(
|
201
|
-
fn=lambda: update_choices("ML"),
|
202
|
-
inputs=None,
|
203
|
-
outputs=[checkbox_group, output_text],
|
246
|
+
filtered_checkbox.select(
|
247
|
+
fn=update_filtered_checkbox_articles,
|
248
|
+
inputs=[filtered_checkbox, filtered_checkbox_state, master_articles_state],
|
249
|
+
outputs=[selected_checkbox, filtered_checkbox_state, master_articles_state]
|
204
250
|
)
|
205
|
-
|
206
|
-
|
207
|
-
fn=
|
208
|
-
inputs=
|
209
|
-
outputs=[
|
251
|
+
|
252
|
+
selected_checkbox.select(
|
253
|
+
fn=update_selected_checkbox_articles,
|
254
|
+
inputs=[selected_checkbox, filtered_checkbox_state, master_articles_state],
|
255
|
+
outputs=[selected_checkbox, filtered_checkbox, master_articles_state, filtered_checkbox_state]
|
210
256
|
)
|
257
|
+
print("Block")
|
258
|
+
|
211
259
|
|
212
|
-
if __name__ ==
|
260
|
+
if __name__ == "__main__":
|
213
261
|
demo.launch()
|
214
262
|
```
|
215
263
|
|
@@ -271,6 +319,19 @@ ChoiceType
|
|
271
319
|
<td align="left">Type of value to be returned by component. "value" returns the list of strings of the choices selected, "index" returns the list of indices of the choices selected.</td>
|
272
320
|
</tr>
|
273
321
|
|
322
|
+
<tr>
|
323
|
+
<td align="left"><code>buttons</code></td>
|
324
|
+
<td align="left" style="width: 25%;">
|
325
|
+
|
326
|
+
```python
|
327
|
+
Optional[List[str]]
|
328
|
+
```
|
329
|
+
|
330
|
+
</td>
|
331
|
+
<td align="left"><code>None</code></td>
|
332
|
+
<td align="left">None</td>
|
333
|
+
</tr>
|
334
|
+
|
274
335
|
<tr>
|
275
336
|
<td align="left"><code>label</code></td>
|
276
337
|
<td align="left" style="width: 25%;">
|