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.
Files changed (23) hide show
  1. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/PKG-INFO +137 -185
  2. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/README.md +136 -184
  3. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/component/index.js +153 -153
  4. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/space.py +136 -184
  5. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/Index.svelte +8 -1
  6. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/pyproject.toml +1 -1
  7. gradio_checkboxgroupmarkdown-0.0.4/demo/app.py +0 -211
  8. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/.gitignore +0 -0
  9. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/__init__.py +0 -0
  10. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/checkboxgroupmarkdown.py +0 -0
  11. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/checkboxgroupmarkdown.pyi +0 -0
  12. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/component/style.css +0 -0
  13. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/example/index.js +0 -0
  14. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/backend/gradio_checkboxgroupmarkdown/templates/example/style.css +0 -0
  15. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/__init__.py +0 -0
  16. /gradio_checkboxgroupmarkdown-0.0.4/demo/old_origin_demo_app.py → /gradio_checkboxgroupmarkdown-0.0.6/demo/app.py +0 -0
  17. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/css.css +0 -0
  18. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/demo/requirements.txt +0 -0
  19. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/Example.svelte +0 -0
  20. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/gradio.config.js +0 -0
  21. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/package-lock.json +0 -0
  22. {gradio_checkboxgroupmarkdown-0.0.4 → gradio_checkboxgroupmarkdown-0.0.6}/frontend/package.json +0 -0
  23. {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.4
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
- 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
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
- def update_filtered_articles(search_text: str, master_articles: List[Dict]):
103
- print("update_filtered_articles")
104
-
105
- """Update the first CheckboxGroupMarkdown with filtered articles"""
106
- filtered = search_articles(search_text, master_articles)
107
-
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
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
- 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"]]
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
- # 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
- ]
122
+ if not selected:
123
+ return "You haven't selected any articles yet."
186
124
 
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
- }
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 Search and Selection Demo")
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
- search_input = gr.Textbox(
208
- label="Search Articles",
209
- placeholder="Enter search terms...",
210
- show_label=True
211
- )
212
- search_button = gr.Button("Search")
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
- # 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",
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.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"]
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
- 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]
187
+ checkbox_group.change(
188
+ fn=sentence_builder,
189
+ inputs=checkbox_group,
190
+ outputs=output_text
244
191
  )
245
192
 
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]
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
- 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]
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__ == "__main__":
212
+ if __name__ == '__main__':
261
213
  demo.launch()
262
214
  ```
263
215