gradio-checkboxgroupmarkdown 0.0.4__tar.gz → 0.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/PKG-INFO +137 -185
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/README.md +136 -184
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/component/index.js +153 -153
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/space.py +136 -184
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/Index.svelte +8 -1
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/pyproject.toml +1 -1
- gradio_checkboxgroupmarkdown-0.0.4/demo/app.py +0 -211
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/.gitignore +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/__init__.py +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/checkboxgroupmarkdown.py +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/checkboxgroupmarkdown.pyi +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/component/style.css +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/example/index.js +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/example/style.css +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/__init__.py +0 -0
- /gradio_checkboxgroupmarkdown-0.0.4/demo/old_origin_demo_app.py → /gradio_checkboxgroupmarkdown-0.0.6/demo/app.py +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/css.css +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/requirements.txt +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/Example.svelte +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/gradio.config.js +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/package-lock.json +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/package.json +0 -0
- {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/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.6
|
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,216 +48,168 @@ pip install gradio_checkboxgroupmarkdown
|
|
48
48
|
## Usage
|
49
49
|
|
50
50
|
```python
|
51
|
+
|
51
52
|
import gradio as gr
|
53
|
+
|
54
|
+
|
55
|
+
from typing import List
|
56
|
+
import gradio as gr
|
57
|
+
from dataclasses import dataclass
|
52
58
|
import random
|
53
|
-
from typing import List, Dict
|
54
59
|
from gradio_checkboxgroupmarkdown import CheckboxGroupMarkdown
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
"id": article_id,
|
78
|
-
"title": title,
|
79
|
-
"content": content,
|
80
|
-
"selected": False
|
81
|
-
})
|
82
|
-
|
83
|
-
return articles
|
84
|
-
|
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
|
61
|
+
# Define two different sets of choices
|
62
|
+
ai_choices = [
|
63
|
+
{
|
64
|
+
"id": "art_101",
|
65
|
+
"title": "Understanding Neural Networks",
|
66
|
+
"content": "# Understanding Neural Networks\nThis article explains the basics of neural networks, their architecture, and how they learn from data.",
|
67
|
+
"selected": False
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"id": "art_102",
|
71
|
+
"title": "A Gentle Introduction to Transformers",
|
72
|
+
"content": "# A Gentle Introduction to Transformers\nTransformers have revolutionized NLP. Learn about attention mechanisms, encoder-decoder architecture, and more.",
|
73
|
+
"selected": False
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"id": "art_103",
|
77
|
+
"title": "Reinforcement Learning Basics",
|
78
|
+
"content": "# Reinforcement Learning Basics\nAn overview of RL concepts like agents, environments, rewards, and policies.",
|
79
|
+
"selected": False
|
80
|
+
}
|
81
|
+
]
|
101
82
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
83
|
+
ml_choices = [
|
84
|
+
{
|
85
|
+
"id": "art_104",
|
86
|
+
"title": "Machine Learning Fundamentals",
|
87
|
+
"content": "# Machine Learning Fundamentals\nLearn about supervised, unsupervised, and reinforcement learning approaches.",
|
88
|
+
"selected": False
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"id": "art_105",
|
92
|
+
"title": "Deep Learning vs Traditional ML",
|
93
|
+
"content": "# Deep Learning vs Traditional ML\nUnderstand the key differences between deep learning and traditional machine learning.",
|
94
|
+
"selected": False
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"id": "art_106",
|
98
|
+
"title": "Feature Engineering",
|
99
|
+
"content": "# Feature Engineering\nMaster the art of creating meaningful features from raw data.",
|
100
|
+
"selected": False
|
114
101
|
}
|
102
|
+
]
|
103
|
+
|
104
|
+
# def sentence_builder(selected):
|
105
|
+
# if not selected:
|
106
|
+
# return "You haven't selected any articles yet."
|
115
107
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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"]]
|
108
|
+
# if isinstance(selected[0], dict) and "title" in selected[0]:
|
109
|
+
# formatted_choices = []
|
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)
|
174
121
|
|
175
|
-
|
176
|
-
|
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
|
-
]
|
122
|
+
if not selected:
|
123
|
+
return "You haven't selected any articles yet."
|
186
124
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
125
|
+
if isinstance(selected[0], dict) and "title" in selected[0]:
|
126
|
+
formatted_choices = []
|
127
|
+
for choice in selected:
|
128
|
+
print(f"Processing choice: {choice}")
|
129
|
+
formatted_choices.append(
|
130
|
+
f"ID: {choice['id']}\nTitle: {choice['title']}\nContent: {choice['content']}"
|
131
|
+
)
|
132
|
+
return "Selected articles are:\n\n" + "\n\n".join(formatted_choices)
|
133
|
+
else:
|
134
|
+
return "Selected articles are:\n\n- " + "\n- ".join(selected)
|
135
|
+
|
136
|
+
def update_choices(choice_type: str):
|
137
|
+
if choice_type == "AI":
|
138
|
+
return gr.update(choices=ai_choices, value=[]), ""
|
139
|
+
elif choice_type == "ML":
|
140
|
+
return gr.update(choices=ml_choices, value=["art_106"]), ""
|
141
|
+
else: # Random mix
|
142
|
+
mixed_choices = random.sample(ai_choices + ml_choices, 3)
|
143
|
+
return gr.update(choices=mixed_choices, value=[]), ""
|
144
|
+
|
145
|
+
# def update_choices(choice_type: str):
|
146
|
+
# if choice_type == "AI":
|
147
|
+
# choices = [{**c, "selected": False} for c in ai_choices]
|
148
|
+
# return gr.update(choices=choices, value=[]), ""
|
149
|
+
# elif choice_type == "ML":
|
150
|
+
# choices = [{**c, "selected": c["id"] == "art_106"} for c in ml_choices]
|
151
|
+
# return gr.update(choices=choices, value=["art_106"]), ""
|
152
|
+
# else: # Random mix
|
153
|
+
# mixed = random.sample(ai_choices + ml_choices, 3)
|
154
|
+
# choices = [{**c, "selected": False} for c in mixed]
|
155
|
+
# return gr.update(choices=choices, value=[]), ""
|
195
156
|
|
196
|
-
# Create the Gradio interface
|
197
157
|
with gr.Blocks() as demo:
|
198
|
-
gr.Markdown("## Article
|
158
|
+
gr.Markdown("## Interactive Article Selection Demo")
|
199
159
|
|
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")
|
204
|
-
|
205
|
-
# Search bar
|
206
160
|
with gr.Row():
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
161
|
+
with gr.Column(scale=1):
|
162
|
+
gr.Markdown("### Change Article Categories")
|
163
|
+
with gr.Row():
|
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")
|
213
167
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
info="Select articles to add to your collection",
|
168
|
+
with gr.Row():
|
169
|
+
with gr.Column(scale=2):
|
170
|
+
checkbox_group = CheckboxGroupMarkdown(
|
171
|
+
choices=ai_choices, # Start with AI choices
|
172
|
+
label="Select Articles",
|
173
|
+
info="Choose articles to include in your collection",
|
221
174
|
type="all",
|
222
|
-
value=[art["id"] for art in master_articles_state.value if art["selected"]],
|
223
175
|
buttons=["select_all", "deselect_all"]
|
224
176
|
)
|
225
|
-
print("filtered_checkbox")
|
226
177
|
|
227
|
-
with gr.
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
info="
|
232
|
-
|
233
|
-
value=[art["id"] for art in master_articles_state.value if art["selected"]],
|
234
|
-
buttons=["select_all", "deselect_all"]
|
178
|
+
with gr.Column(scale=1):
|
179
|
+
output_text = gr.Textbox(
|
180
|
+
label="Selected Articles",
|
181
|
+
placeholder="Make selections to see results...",
|
182
|
+
info="Selected articles will be displayed here",
|
183
|
+
lines=10
|
235
184
|
)
|
236
|
-
print("selected_checkbox")
|
237
185
|
|
238
186
|
# Event handlers
|
239
|
-
|
240
|
-
fn=
|
241
|
-
inputs=
|
242
|
-
|
243
|
-
outputs=[filtered_checkbox, filtered_checkbox_state]
|
187
|
+
checkbox_group.change(
|
188
|
+
fn=sentence_builder,
|
189
|
+
inputs=checkbox_group,
|
190
|
+
outputs=output_text
|
244
191
|
)
|
245
192
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
193
|
+
# Button click handlers to update choices
|
194
|
+
ai_btn.click(
|
195
|
+
fn=lambda: update_choices("AI"),
|
196
|
+
inputs=None,
|
197
|
+
outputs=[checkbox_group, output_text],
|
250
198
|
)
|
251
|
-
|
252
|
-
|
253
|
-
fn=
|
254
|
-
inputs=
|
255
|
-
outputs=[
|
199
|
+
|
200
|
+
ml_btn.click(
|
201
|
+
fn=lambda: update_choices("ML"),
|
202
|
+
inputs=None,
|
203
|
+
outputs=[checkbox_group, output_text],
|
204
|
+
)
|
205
|
+
|
206
|
+
mix_btn.click(
|
207
|
+
fn=lambda: update_choices("MIX"),
|
208
|
+
inputs=None,
|
209
|
+
outputs=[checkbox_group, output_text],
|
256
210
|
)
|
257
|
-
print("Block")
|
258
|
-
|
259
211
|
|
260
|
-
if __name__ ==
|
212
|
+
if __name__ == '__main__':
|
261
213
|
demo.launch()
|
262
214
|
```
|
263
215
|
|