Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- README.md +72 -122
- app.py +65 -115
- space.py +72 -122
- src/CLAUDE.local.md +51 -0
- src/README.md +72 -122
- src/backend/gradio_markdownlabel/templates/component/index.js +0 -0
- src/demo/app.py +65 -115
- src/demo/space.py +72 -122
- src/frontend/shared/EditableMarkdownRenderer.svelte +59 -24
- src/frontend/shared/MarkdownRenderer.svelte +51 -22
- src/pyproject.toml +1 -1
README.md
CHANGED
|
@@ -27,150 +27,100 @@ pip install gradio_markdownlabel
|
|
| 27 |
import gradio as gr
|
| 28 |
from gradio_markdownlabel import MarkdownLabel
|
| 29 |
|
| 30 |
-
# Create a comprehensive example with rich markdown content and multiple highlights
|
| 31 |
-
example_data = {
|
| 32 |
-
"markdown_content": """# AI and Machine Learning Research Report
|
| 33 |
-
|
| 34 |
-
## Introduction
|
| 35 |
-
|
| 36 |
-
This document explores the rapidly evolving field of **artificial intelligence** and its various applications in modern technology. The study focuses on *machine learning* techniques and their impact on different industries.
|
| 37 |
-
|
| 38 |
-
## Key Technologies
|
| 39 |
-
|
| 40 |
-
### Deep Learning
|
| 41 |
-
*Deep learning* represents a subset of machine learning that uses **neural networks** with multiple layers. This approach has revolutionized areas such as:
|
| 42 |
-
|
| 43 |
-
- Computer vision
|
| 44 |
-
- Natural language processing
|
| 45 |
-
- Speech recognition
|
| 46 |
-
|
| 47 |
-
### Natural Language Processing
|
| 48 |
-
**Natural language processing** (NLP) enables computers to understand and interpret human language. Key applications include:
|
| 49 |
-
|
| 50 |
-
1. Text analysis
|
| 51 |
-
2. Sentiment analysis
|
| 52 |
-
3. Language translation
|
| 53 |
-
|
| 54 |
-
## Applications
|
| 55 |
-
|
| 56 |
-
The integration of **computer vision** in autonomous vehicles has transformed the automotive industry. Similarly, **reinforcement learning** has shown remarkable success in gaming and robotics.
|
| 57 |
-
|
| 58 |
-
## Conclusion
|
| 59 |
-
|
| 60 |
-
As **artificial intelligence** continues to advance, we expect to see more sophisticated applications of these technologies across various domains.
|
| 61 |
-
""",
|
| 62 |
-
"highlights": [
|
| 63 |
-
{
|
| 64 |
-
"term": "artificial intelligence",
|
| 65 |
-
"title": "Artificial Intelligence (AI)",
|
| 66 |
-
"content": "**Artificial Intelligence** refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. AI systems can perform tasks that typically require human intelligence, such as:\n\n- Visual perception\n- Speech recognition\n- Decision-making\n- Language translation\n\nAI is broadly categorized into:\n1. **Narrow AI** - designed for specific tasks\n2. **General AI** - hypothetical AI with human-level cognitive abilities",
|
| 67 |
-
"category": "Core Technology",
|
| 68 |
-
"color": "#e3f2fd"
|
| 69 |
-
},
|
| 70 |
-
{
|
| 71 |
-
"term": "machine learning",
|
| 72 |
-
"title": "Machine Learning (ML)",
|
| 73 |
-
"content": "**Machine Learning** is a subset of AI that focuses on the development of algorithms that can learn and improve from experience without being explicitly programmed.\n\n### Types of Machine Learning:\n- **Supervised Learning**: Learning with labeled examples\n- **Unsupervised Learning**: Finding patterns in unlabeled data\n- **Reinforcement Learning**: Learning through interaction with environment\n\n### Applications:\n- Recommendation systems\n- Fraud detection\n- Medical diagnosis\n- Autonomous vehicles",
|
| 74 |
-
"category": "Core Technology",
|
| 75 |
-
"color": "#f3e5f5"
|
| 76 |
-
},
|
| 77 |
-
{
|
| 78 |
-
"term": "deep learning",
|
| 79 |
-
"title": "Deep Learning",
|
| 80 |
-
"content": "**Deep Learning** is a specialized subset of machine learning that uses artificial neural networks with multiple layers (deep neural networks) to model and understand complex patterns.\n\n### Key Characteristics:\n- Multiple hidden layers\n- Automatic feature extraction\n- Hierarchical learning\n\n### Popular Architectures:\n- Convolutional Neural Networks (CNNs)\n- Recurrent Neural Networks (RNNs)\n- Transformers\n\n### Applications:\n- Image recognition\n- Natural language processing\n- Speech synthesis",
|
| 81 |
-
"category": "Advanced Technique",
|
| 82 |
-
"color": "#e8f5e8"
|
| 83 |
-
},
|
| 84 |
-
{
|
| 85 |
-
"term": "neural networks",
|
| 86 |
-
"title": "Neural Networks",
|
| 87 |
-
"content": "**Neural Networks** are computing systems inspired by biological neural networks. They consist of interconnected nodes (neurons) that process information.\n\n### Components:\n- **Input Layer**: Receives data\n- **Hidden Layers**: Process information\n- **Output Layer**: Produces results\n\n### Types:\n- Feedforward networks\n- Recurrent networks\n- Convolutional networks\n\nNeural networks learn by adjusting the weights of connections between neurons based on training data.",
|
| 88 |
-
"category": "Architecture",
|
| 89 |
-
"color": "#fff3e0"
|
| 90 |
-
},
|
| 91 |
-
{
|
| 92 |
-
"term": "natural language processing",
|
| 93 |
-
"title": "Natural Language Processing (NLP)",
|
| 94 |
-
"content": "**Natural Language Processing** combines computational linguistics with machine learning to enable computers to understand, interpret, and generate human language.\n\n### Core Tasks:\n- **Tokenization**: Breaking text into words/sentences\n- **Part-of-speech tagging**: Identifying grammatical roles\n- **Named entity recognition**: Identifying people, places, organizations\n- **Sentiment analysis**: Determining emotional tone\n\n### Modern Approaches:\n- Transformer models (BERT, GPT)\n- Attention mechanisms\n- Pre-trained language models",
|
| 95 |
-
"category": "Application Domain",
|
| 96 |
-
"color": "#fce4ec"
|
| 97 |
-
},
|
| 98 |
-
{
|
| 99 |
-
"position": [615, 632],
|
| 100 |
-
"title": "Computer Vision (Position-based)",
|
| 101 |
-
"content": "**Computer Vision** highlighted by character position rather than term matching. This demonstrates precise control over highlighting specific text segments.\n\n### Position-based Benefits:\n- Exact character-level precision\n- No ambiguity with similar terms\n- Works with any text, including special characters\n- Useful for pre-processed documents",
|
| 102 |
-
"category": "Position Highlight",
|
| 103 |
-
"color": "#ffeb3b"
|
| 104 |
-
},
|
| 105 |
-
{
|
| 106 |
-
"term": "computer vision",
|
| 107 |
-
"title": "Computer Vision",
|
| 108 |
-
"content": "**Computer Vision** is a field of AI that enables machines to interpret and understand visual information from the world, mimicking human vision capabilities.\n\n### Key Tasks:\n- **Object Detection**: Locating objects in images\n- **Image Classification**: Categorizing images\n- **Semantic Segmentation**: Pixel-level understanding\n- **Face Recognition**: Identifying individuals\n\n### Applications:\n- Autonomous vehicles\n- Medical imaging\n- Security systems\n- Augmented reality",
|
| 109 |
-
"category": "Application Domain",
|
| 110 |
-
"color": "#e1f5fe"
|
| 111 |
-
},
|
| 112 |
-
{
|
| 113 |
-
"term": "reinforcement learning",
|
| 114 |
-
"title": "Reinforcement Learning (RL)",
|
| 115 |
-
"content": "**Reinforcement Learning** is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize cumulative reward.\n\n### Key Concepts:\n- **Agent**: The learner/decision maker\n- **Environment**: The world the agent interacts with\n- **Actions**: Choices available to the agent\n- **Rewards**: Feedback from the environment\n- **Policy**: Strategy for choosing actions\n\n### Famous Applications:\n- Game playing (AlphaGo, OpenAI Five)\n- Robotics control\n- Trading algorithms\n- Resource allocation",
|
| 116 |
-
"category": "Learning Paradigm",
|
| 117 |
-
"color": "#f1f8e9"
|
| 118 |
-
},
|
| 119 |
-
{
|
| 120 |
-
"position": [169, 190],
|
| 121 |
-
"title": "Machine Learning (Position)",
|
| 122 |
-
"content": "This **machine learning** instance is highlighted using position-based highlighting at characters 169-190.\n\n### Position Highlighting Use Cases:\n- Academic paper annotations\n- Legal document markup\n- Code documentation\n- Precise text analysis\n\nPosition-based highlighting ensures exact text selection without ambiguity.",
|
| 123 |
-
"category": "Position Demo",
|
| 124 |
-
"color": "#e8eaf6"
|
| 125 |
-
}
|
| 126 |
-
]
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 130 |
gr.Markdown("# MarkdownLabel Component Demo")
|
| 131 |
-
gr.Markdown("This demo showcases the MarkdownLabel component with **both term-based and position-based** interactive highlighting and detailed side panel.")
|
| 132 |
-
|
| 133 |
-
gr.Markdown("Includes both term-based (e.g., 'artificial intelligence') and position-based highlighting (yellow highlights).")
|
| 134 |
-
MarkdownLabel(
|
| 135 |
-
value=example_data,
|
| 136 |
-
label="AI Research Report - Mixed Highlighting",
|
| 137 |
-
show_side_panel=True,
|
| 138 |
-
panel_width="350px",
|
| 139 |
-
interactive=True
|
| 140 |
-
)
|
| 141 |
|
| 142 |
# Simple position-based example
|
| 143 |
-
|
| 144 |
-
"markdown_content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
"highlights": [
|
| 146 |
{
|
| 147 |
-
"position": [
|
| 148 |
-
"title": "Quick
|
| 149 |
-
"content": "Highlighted using exact character positions
|
| 150 |
"category": "Position Demo",
|
| 151 |
"color": "#ffeb3b"
|
| 152 |
},
|
| 153 |
{
|
| 154 |
"term": "brown fox",
|
| 155 |
"title": "Brown Fox (Term Match)",
|
| 156 |
-
"content": "Highlighted using term matching.",
|
| 157 |
"category": "Term Demo",
|
| 158 |
"color": "#e3f2fd"
|
| 159 |
},
|
| 160 |
{
|
| 161 |
-
"position": [
|
| 162 |
-
"title": "
|
| 163 |
-
"content": "
|
| 164 |
"category": "Position Demo",
|
| 165 |
-
"color": "#
|
| 166 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
]
|
| 168 |
}
|
| 169 |
|
| 170 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 171 |
-
gr.Markdown("This example shows the difference between position-based (yellow
|
| 172 |
MarkdownLabel(
|
| 173 |
-
value=
|
| 174 |
label="Simple Position vs Term Example",
|
| 175 |
show_side_panel=True,
|
| 176 |
panel_width="300px",
|
|
|
|
| 27 |
import gradio as gr
|
| 28 |
from gradio_markdownlabel import MarkdownLabel
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 31 |
gr.Markdown("# MarkdownLabel Component Demo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Simple position-based example
|
| 34 |
+
example = {
|
| 35 |
+
"markdown_content": """# Comprehensive Markdown Example
|
| 36 |
+
|
| 37 |
+
## Introduction
|
| 38 |
+
*The* quick **brown fox** jumps over the lazy dog. This is a simple quick example with various **formatting** elements.
|
| 39 |
+
|
| 40 |
+
### Lists and Items
|
| 41 |
+
Here are some important points:
|
| 42 |
+
|
| 43 |
+
1. **First item** - This is the primary consideration
|
| 44 |
+
2. *Second item* - Another important point
|
| 45 |
+
3. Third item with `inline code`
|
| 46 |
+
4. Fourth item containing [a link](https://example.com)
|
| 47 |
+
|
| 48 |
+
#### Unordered Lists
|
| 49 |
+
- Bullet point one
|
| 50 |
+
- Bullet point two with **bold text**
|
| 51 |
+
- Final bullet point
|
| 52 |
+
|
| 53 |
+
### Code Block Example
|
| 54 |
+
```python
|
| 55 |
+
def hello_world():
|
| 56 |
+
print("Hello, World!")
|
| 57 |
+
return "success"
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### Tables
|
| 61 |
+
| Column 1 | Column 2 | Column 3 |
|
| 62 |
+
|----------|----------|----------|
|
| 63 |
+
| Cell 1 | Cell 2 | Cell 3 |
|
| 64 |
+
| Data A | Data B | Data C |
|
| 65 |
+
|
| 66 |
+
### Blockquotes
|
| 67 |
+
> This is a blockquote with some **important** information.
|
| 68 |
+
>
|
| 69 |
+
> It can span multiple lines and contain *emphasis*.
|
| 70 |
+
|
| 71 |
+
### Mixed Content
|
| 72 |
+
The document contains various **formatting** options including:
|
| 73 |
+
|
| 74 |
+
- *Italicized text* for emphasis
|
| 75 |
+
- **Bold text** for importance
|
| 76 |
+
- `Inline code` for technical terms
|
| 77 |
+
- Links like [this one](https://example.com)
|
| 78 |
+
|
| 79 |
+
#### Final Section
|
| 80 |
+
This concludes our comprehensive example with multiple markdown elements for testing position-based highlighting accuracy.""",
|
| 81 |
"highlights": [
|
| 82 |
{
|
| 83 |
+
"position": [56, 61], # "quick" in "The quick brown fox", note the 2nd quick is not highlighted
|
| 84 |
+
"title": "Quick",
|
| 85 |
+
"content": "Highlighted using exact character positions.",
|
| 86 |
"category": "Position Demo",
|
| 87 |
"color": "#ffeb3b"
|
| 88 |
},
|
| 89 |
{
|
| 90 |
"term": "brown fox",
|
| 91 |
"title": "Brown Fox (Term Match)",
|
| 92 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 93 |
"category": "Term Demo",
|
| 94 |
"color": "#e3f2fd"
|
| 95 |
},
|
| 96 |
{
|
| 97 |
+
"position": [91, 95], # "lazy" in "the lazy dog"
|
| 98 |
+
"title": "Lazy",
|
| 99 |
+
"content": "Position-based highlight",
|
| 100 |
"category": "Position Demo",
|
| 101 |
+
"color": "#ffeb3b"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"position": [989, 999],
|
| 105 |
+
"title": "Italicized",
|
| 106 |
+
"content": "Highlighting 'Italicized'",
|
| 107 |
+
"category": "Position Demo",
|
| 108 |
+
"color": "#ff9800"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"term": "formatting",
|
| 112 |
+
"title": "formatting (Term Match)",
|
| 113 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 114 |
+
"category": "Term Demo",
|
| 115 |
+
"color": "#d0167f91"
|
| 116 |
+
},
|
| 117 |
]
|
| 118 |
}
|
| 119 |
|
| 120 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 121 |
+
gr.Markdown("This example shows the difference between position-based (yellow) and term-based (blue) highlighting.")
|
| 122 |
MarkdownLabel(
|
| 123 |
+
value=example,
|
| 124 |
label="Simple Position vs Term Example",
|
| 125 |
show_side_panel=True,
|
| 126 |
panel_width="300px",
|
app.py
CHANGED
|
@@ -2,150 +2,100 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_markdownlabel import MarkdownLabel
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
## Introduction
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
## Key Technologies
|
| 14 |
-
|
| 15 |
-
### Deep Learning
|
| 16 |
-
*Deep learning* represents a subset of machine learning that uses **neural networks** with multiple layers. This approach has revolutionized areas such as:
|
| 17 |
|
| 18 |
-
-
|
| 19 |
-
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
"term": "artificial intelligence",
|
| 40 |
-
"title": "Artificial Intelligence (AI)",
|
| 41 |
-
"content": "**Artificial Intelligence** refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. AI systems can perform tasks that typically require human intelligence, such as:\n\n- Visual perception\n- Speech recognition\n- Decision-making\n- Language translation\n\nAI is broadly categorized into:\n1. **Narrow AI** - designed for specific tasks\n2. **General AI** - hypothetical AI with human-level cognitive abilities",
|
| 42 |
-
"category": "Core Technology",
|
| 43 |
-
"color": "#e3f2fd"
|
| 44 |
-
},
|
| 45 |
-
{
|
| 46 |
-
"term": "machine learning",
|
| 47 |
-
"title": "Machine Learning (ML)",
|
| 48 |
-
"content": "**Machine Learning** is a subset of AI that focuses on the development of algorithms that can learn and improve from experience without being explicitly programmed.\n\n### Types of Machine Learning:\n- **Supervised Learning**: Learning with labeled examples\n- **Unsupervised Learning**: Finding patterns in unlabeled data\n- **Reinforcement Learning**: Learning through interaction with environment\n\n### Applications:\n- Recommendation systems\n- Fraud detection\n- Medical diagnosis\n- Autonomous vehicles",
|
| 49 |
-
"category": "Core Technology",
|
| 50 |
-
"color": "#f3e5f5"
|
| 51 |
-
},
|
| 52 |
-
{
|
| 53 |
-
"term": "deep learning",
|
| 54 |
-
"title": "Deep Learning",
|
| 55 |
-
"content": "**Deep Learning** is a specialized subset of machine learning that uses artificial neural networks with multiple layers (deep neural networks) to model and understand complex patterns.\n\n### Key Characteristics:\n- Multiple hidden layers\n- Automatic feature extraction\n- Hierarchical learning\n\n### Popular Architectures:\n- Convolutional Neural Networks (CNNs)\n- Recurrent Neural Networks (RNNs)\n- Transformers\n\n### Applications:\n- Image recognition\n- Natural language processing\n- Speech synthesis",
|
| 56 |
-
"category": "Advanced Technique",
|
| 57 |
-
"color": "#e8f5e8"
|
| 58 |
-
},
|
| 59 |
-
{
|
| 60 |
-
"term": "neural networks",
|
| 61 |
-
"title": "Neural Networks",
|
| 62 |
-
"content": "**Neural Networks** are computing systems inspired by biological neural networks. They consist of interconnected nodes (neurons) that process information.\n\n### Components:\n- **Input Layer**: Receives data\n- **Hidden Layers**: Process information\n- **Output Layer**: Produces results\n\n### Types:\n- Feedforward networks\n- Recurrent networks\n- Convolutional networks\n\nNeural networks learn by adjusting the weights of connections between neurons based on training data.",
|
| 63 |
-
"category": "Architecture",
|
| 64 |
-
"color": "#fff3e0"
|
| 65 |
-
},
|
| 66 |
-
{
|
| 67 |
-
"term": "natural language processing",
|
| 68 |
-
"title": "Natural Language Processing (NLP)",
|
| 69 |
-
"content": "**Natural Language Processing** combines computational linguistics with machine learning to enable computers to understand, interpret, and generate human language.\n\n### Core Tasks:\n- **Tokenization**: Breaking text into words/sentences\n- **Part-of-speech tagging**: Identifying grammatical roles\n- **Named entity recognition**: Identifying people, places, organizations\n- **Sentiment analysis**: Determining emotional tone\n\n### Modern Approaches:\n- Transformer models (BERT, GPT)\n- Attention mechanisms\n- Pre-trained language models",
|
| 70 |
-
"category": "Application Domain",
|
| 71 |
-
"color": "#fce4ec"
|
| 72 |
-
},
|
| 73 |
-
{
|
| 74 |
-
"position": [615, 632],
|
| 75 |
-
"title": "Computer Vision (Position-based)",
|
| 76 |
-
"content": "**Computer Vision** highlighted by character position rather than term matching. This demonstrates precise control over highlighting specific text segments.\n\n### Position-based Benefits:\n- Exact character-level precision\n- No ambiguity with similar terms\n- Works with any text, including special characters\n- Useful for pre-processed documents",
|
| 77 |
-
"category": "Position Highlight",
|
| 78 |
-
"color": "#ffeb3b"
|
| 79 |
-
},
|
| 80 |
-
{
|
| 81 |
-
"term": "computer vision",
|
| 82 |
-
"title": "Computer Vision",
|
| 83 |
-
"content": "**Computer Vision** is a field of AI that enables machines to interpret and understand visual information from the world, mimicking human vision capabilities.\n\n### Key Tasks:\n- **Object Detection**: Locating objects in images\n- **Image Classification**: Categorizing images\n- **Semantic Segmentation**: Pixel-level understanding\n- **Face Recognition**: Identifying individuals\n\n### Applications:\n- Autonomous vehicles\n- Medical imaging\n- Security systems\n- Augmented reality",
|
| 84 |
-
"category": "Application Domain",
|
| 85 |
-
"color": "#e1f5fe"
|
| 86 |
-
},
|
| 87 |
-
{
|
| 88 |
-
"term": "reinforcement learning",
|
| 89 |
-
"title": "Reinforcement Learning (RL)",
|
| 90 |
-
"content": "**Reinforcement Learning** is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize cumulative reward.\n\n### Key Concepts:\n- **Agent**: The learner/decision maker\n- **Environment**: The world the agent interacts with\n- **Actions**: Choices available to the agent\n- **Rewards**: Feedback from the environment\n- **Policy**: Strategy for choosing actions\n\n### Famous Applications:\n- Game playing (AlphaGo, OpenAI Five)\n- Robotics control\n- Trading algorithms\n- Resource allocation",
|
| 91 |
-
"category": "Learning Paradigm",
|
| 92 |
-
"color": "#f1f8e9"
|
| 93 |
-
},
|
| 94 |
-
{
|
| 95 |
-
"position": [169, 190],
|
| 96 |
-
"title": "Machine Learning (Position)",
|
| 97 |
-
"content": "This **machine learning** instance is highlighted using position-based highlighting at characters 169-190.\n\n### Position Highlighting Use Cases:\n- Academic paper annotations\n- Legal document markup\n- Code documentation\n- Precise text analysis\n\nPosition-based highlighting ensures exact text selection without ambiguity.",
|
| 98 |
-
"category": "Position Demo",
|
| 99 |
-
"color": "#e8eaf6"
|
| 100 |
-
}
|
| 101 |
-
]
|
| 102 |
-
}
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
gr.Markdown("This demo showcases the MarkdownLabel component with **both term-based and position-based** interactive highlighting and detailed side panel.")
|
| 107 |
-
|
| 108 |
-
gr.Markdown("Includes both term-based (e.g., 'artificial intelligence') and position-based highlighting (yellow highlights).")
|
| 109 |
-
MarkdownLabel(
|
| 110 |
-
value=example_data,
|
| 111 |
-
label="AI Research Report - Mixed Highlighting",
|
| 112 |
-
show_side_panel=True,
|
| 113 |
-
panel_width="350px",
|
| 114 |
-
interactive=True
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
# Simple position-based example
|
| 118 |
-
simple_example = {
|
| 119 |
-
"markdown_content": "The quick **brown fox** jumps over the lazy dog. This is a simple example.",
|
| 120 |
"highlights": [
|
| 121 |
{
|
| 122 |
-
"position": [
|
| 123 |
-
"title": "Quick
|
| 124 |
-
"content": "Highlighted using exact character positions
|
| 125 |
"category": "Position Demo",
|
| 126 |
"color": "#ffeb3b"
|
| 127 |
},
|
| 128 |
{
|
| 129 |
"term": "brown fox",
|
| 130 |
"title": "Brown Fox (Term Match)",
|
| 131 |
-
"content": "Highlighted using term matching.",
|
| 132 |
"category": "Term Demo",
|
| 133 |
"color": "#e3f2fd"
|
| 134 |
},
|
| 135 |
{
|
| 136 |
-
"position": [
|
| 137 |
-
"title": "
|
| 138 |
-
"content": "
|
| 139 |
"category": "Position Demo",
|
| 140 |
-
"color": "#
|
| 141 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
]
|
| 143 |
}
|
| 144 |
|
| 145 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 146 |
-
gr.Markdown("This example shows the difference between position-based (yellow
|
| 147 |
MarkdownLabel(
|
| 148 |
-
value=
|
| 149 |
label="Simple Position vs Term Example",
|
| 150 |
show_side_panel=True,
|
| 151 |
panel_width="300px",
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_markdownlabel import MarkdownLabel
|
| 4 |
|
| 5 |
+
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 6 |
+
gr.Markdown("# MarkdownLabel Component Demo")
|
| 7 |
+
|
| 8 |
+
# Simple position-based example
|
| 9 |
+
example = {
|
| 10 |
+
"markdown_content": """# Comprehensive Markdown Example
|
| 11 |
|
| 12 |
## Introduction
|
| 13 |
+
*The* quick **brown fox** jumps over the lazy dog. This is a simple quick example with various **formatting** elements.
|
| 14 |
|
| 15 |
+
### Lists and Items
|
| 16 |
+
Here are some important points:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
1. **First item** - This is the primary consideration
|
| 19 |
+
2. *Second item* - Another important point
|
| 20 |
+
3. Third item with `inline code`
|
| 21 |
+
4. Fourth item containing [a link](https://example.com)
|
| 22 |
|
| 23 |
+
#### Unordered Lists
|
| 24 |
+
- Bullet point one
|
| 25 |
+
- Bullet point two with **bold text**
|
| 26 |
+
- Final bullet point
|
| 27 |
|
| 28 |
+
### Code Block Example
|
| 29 |
+
```python
|
| 30 |
+
def hello_world():
|
| 31 |
+
print("Hello, World!")
|
| 32 |
+
return "success"
|
| 33 |
+
```
|
| 34 |
|
| 35 |
+
### Tables
|
| 36 |
+
| Column 1 | Column 2 | Column 3 |
|
| 37 |
+
|----------|----------|----------|
|
| 38 |
+
| Cell 1 | Cell 2 | Cell 3 |
|
| 39 |
+
| Data A | Data B | Data C |
|
| 40 |
|
| 41 |
+
### Blockquotes
|
| 42 |
+
> This is a blockquote with some **important** information.
|
| 43 |
+
>
|
| 44 |
+
> It can span multiple lines and contain *emphasis*.
|
| 45 |
|
| 46 |
+
### Mixed Content
|
| 47 |
+
The document contains various **formatting** options including:
|
| 48 |
|
| 49 |
+
- *Italicized text* for emphasis
|
| 50 |
+
- **Bold text** for importance
|
| 51 |
+
- `Inline code` for technical terms
|
| 52 |
+
- Links like [this one](https://example.com)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
#### Final Section
|
| 55 |
+
This concludes our comprehensive example with multiple markdown elements for testing position-based highlighting accuracy.""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
"highlights": [
|
| 57 |
{
|
| 58 |
+
"position": [56, 61], # "quick" in "The quick brown fox", note the 2nd quick is not highlighted
|
| 59 |
+
"title": "Quick",
|
| 60 |
+
"content": "Highlighted using exact character positions.",
|
| 61 |
"category": "Position Demo",
|
| 62 |
"color": "#ffeb3b"
|
| 63 |
},
|
| 64 |
{
|
| 65 |
"term": "brown fox",
|
| 66 |
"title": "Brown Fox (Term Match)",
|
| 67 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 68 |
"category": "Term Demo",
|
| 69 |
"color": "#e3f2fd"
|
| 70 |
},
|
| 71 |
{
|
| 72 |
+
"position": [91, 95], # "lazy" in "the lazy dog"
|
| 73 |
+
"title": "Lazy",
|
| 74 |
+
"content": "Position-based highlight",
|
| 75 |
"category": "Position Demo",
|
| 76 |
+
"color": "#ffeb3b"
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
"position": [989, 999],
|
| 80 |
+
"title": "Italicized",
|
| 81 |
+
"content": "Highlighting 'Italicized'",
|
| 82 |
+
"category": "Position Demo",
|
| 83 |
+
"color": "#ff9800"
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"term": "formatting",
|
| 87 |
+
"title": "formatting (Term Match)",
|
| 88 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 89 |
+
"category": "Term Demo",
|
| 90 |
+
"color": "#d0167f91"
|
| 91 |
+
},
|
| 92 |
]
|
| 93 |
}
|
| 94 |
|
| 95 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 96 |
+
gr.Markdown("This example shows the difference between position-based (yellow) and term-based (blue) highlighting.")
|
| 97 |
MarkdownLabel(
|
| 98 |
+
value=example,
|
| 99 |
label="Simple Position vs Term Example",
|
| 100 |
show_side_panel=True,
|
| 101 |
panel_width="300px",
|
space.py
CHANGED
|
@@ -42,150 +42,100 @@ pip install gradio_markdownlabel
|
|
| 42 |
import gradio as gr
|
| 43 |
from gradio_markdownlabel import MarkdownLabel
|
| 44 |
|
| 45 |
-
# Create a comprehensive example with rich markdown content and multiple highlights
|
| 46 |
-
example_data = {
|
| 47 |
-
"markdown_content": \"\"\"# AI and Machine Learning Research Report
|
| 48 |
-
|
| 49 |
-
## Introduction
|
| 50 |
-
|
| 51 |
-
This document explores the rapidly evolving field of **artificial intelligence** and its various applications in modern technology. The study focuses on *machine learning* techniques and their impact on different industries.
|
| 52 |
-
|
| 53 |
-
## Key Technologies
|
| 54 |
-
|
| 55 |
-
### Deep Learning
|
| 56 |
-
*Deep learning* represents a subset of machine learning that uses **neural networks** with multiple layers. This approach has revolutionized areas such as:
|
| 57 |
-
|
| 58 |
-
- Computer vision
|
| 59 |
-
- Natural language processing
|
| 60 |
-
- Speech recognition
|
| 61 |
-
|
| 62 |
-
### Natural Language Processing
|
| 63 |
-
**Natural language processing** (NLP) enables computers to understand and interpret human language. Key applications include:
|
| 64 |
-
|
| 65 |
-
1. Text analysis
|
| 66 |
-
2. Sentiment analysis
|
| 67 |
-
3. Language translation
|
| 68 |
-
|
| 69 |
-
## Applications
|
| 70 |
-
|
| 71 |
-
The integration of **computer vision** in autonomous vehicles has transformed the automotive industry. Similarly, **reinforcement learning** has shown remarkable success in gaming and robotics.
|
| 72 |
-
|
| 73 |
-
## Conclusion
|
| 74 |
-
|
| 75 |
-
As **artificial intelligence** continues to advance, we expect to see more sophisticated applications of these technologies across various domains.
|
| 76 |
-
\"\"\",
|
| 77 |
-
"highlights": [
|
| 78 |
-
{
|
| 79 |
-
"term": "artificial intelligence",
|
| 80 |
-
"title": "Artificial Intelligence (AI)",
|
| 81 |
-
"content": "**Artificial Intelligence** refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. AI systems can perform tasks that typically require human intelligence, such as:\n\n- Visual perception\n- Speech recognition\n- Decision-making\n- Language translation\n\nAI is broadly categorized into:\n1. **Narrow AI** - designed for specific tasks\n2. **General AI** - hypothetical AI with human-level cognitive abilities",
|
| 82 |
-
"category": "Core Technology",
|
| 83 |
-
"color": "#e3f2fd"
|
| 84 |
-
},
|
| 85 |
-
{
|
| 86 |
-
"term": "machine learning",
|
| 87 |
-
"title": "Machine Learning (ML)",
|
| 88 |
-
"content": "**Machine Learning** is a subset of AI that focuses on the development of algorithms that can learn and improve from experience without being explicitly programmed.\n\n### Types of Machine Learning:\n- **Supervised Learning**: Learning with labeled examples\n- **Unsupervised Learning**: Finding patterns in unlabeled data\n- **Reinforcement Learning**: Learning through interaction with environment\n\n### Applications:\n- Recommendation systems\n- Fraud detection\n- Medical diagnosis\n- Autonomous vehicles",
|
| 89 |
-
"category": "Core Technology",
|
| 90 |
-
"color": "#f3e5f5"
|
| 91 |
-
},
|
| 92 |
-
{
|
| 93 |
-
"term": "deep learning",
|
| 94 |
-
"title": "Deep Learning",
|
| 95 |
-
"content": "**Deep Learning** is a specialized subset of machine learning that uses artificial neural networks with multiple layers (deep neural networks) to model and understand complex patterns.\n\n### Key Characteristics:\n- Multiple hidden layers\n- Automatic feature extraction\n- Hierarchical learning\n\n### Popular Architectures:\n- Convolutional Neural Networks (CNNs)\n- Recurrent Neural Networks (RNNs)\n- Transformers\n\n### Applications:\n- Image recognition\n- Natural language processing\n- Speech synthesis",
|
| 96 |
-
"category": "Advanced Technique",
|
| 97 |
-
"color": "#e8f5e8"
|
| 98 |
-
},
|
| 99 |
-
{
|
| 100 |
-
"term": "neural networks",
|
| 101 |
-
"title": "Neural Networks",
|
| 102 |
-
"content": "**Neural Networks** are computing systems inspired by biological neural networks. They consist of interconnected nodes (neurons) that process information.\n\n### Components:\n- **Input Layer**: Receives data\n- **Hidden Layers**: Process information\n- **Output Layer**: Produces results\n\n### Types:\n- Feedforward networks\n- Recurrent networks\n- Convolutional networks\n\nNeural networks learn by adjusting the weights of connections between neurons based on training data.",
|
| 103 |
-
"category": "Architecture",
|
| 104 |
-
"color": "#fff3e0"
|
| 105 |
-
},
|
| 106 |
-
{
|
| 107 |
-
"term": "natural language processing",
|
| 108 |
-
"title": "Natural Language Processing (NLP)",
|
| 109 |
-
"content": "**Natural Language Processing** combines computational linguistics with machine learning to enable computers to understand, interpret, and generate human language.\n\n### Core Tasks:\n- **Tokenization**: Breaking text into words/sentences\n- **Part-of-speech tagging**: Identifying grammatical roles\n- **Named entity recognition**: Identifying people, places, organizations\n- **Sentiment analysis**: Determining emotional tone\n\n### Modern Approaches:\n- Transformer models (BERT, GPT)\n- Attention mechanisms\n- Pre-trained language models",
|
| 110 |
-
"category": "Application Domain",
|
| 111 |
-
"color": "#fce4ec"
|
| 112 |
-
},
|
| 113 |
-
{
|
| 114 |
-
"position": [615, 632],
|
| 115 |
-
"title": "Computer Vision (Position-based)",
|
| 116 |
-
"content": "**Computer Vision** highlighted by character position rather than term matching. This demonstrates precise control over highlighting specific text segments.\n\n### Position-based Benefits:\n- Exact character-level precision\n- No ambiguity with similar terms\n- Works with any text, including special characters\n- Useful for pre-processed documents",
|
| 117 |
-
"category": "Position Highlight",
|
| 118 |
-
"color": "#ffeb3b"
|
| 119 |
-
},
|
| 120 |
-
{
|
| 121 |
-
"term": "computer vision",
|
| 122 |
-
"title": "Computer Vision",
|
| 123 |
-
"content": "**Computer Vision** is a field of AI that enables machines to interpret and understand visual information from the world, mimicking human vision capabilities.\n\n### Key Tasks:\n- **Object Detection**: Locating objects in images\n- **Image Classification**: Categorizing images\n- **Semantic Segmentation**: Pixel-level understanding\n- **Face Recognition**: Identifying individuals\n\n### Applications:\n- Autonomous vehicles\n- Medical imaging\n- Security systems\n- Augmented reality",
|
| 124 |
-
"category": "Application Domain",
|
| 125 |
-
"color": "#e1f5fe"
|
| 126 |
-
},
|
| 127 |
-
{
|
| 128 |
-
"term": "reinforcement learning",
|
| 129 |
-
"title": "Reinforcement Learning (RL)",
|
| 130 |
-
"content": "**Reinforcement Learning** is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize cumulative reward.\n\n### Key Concepts:\n- **Agent**: The learner/decision maker\n- **Environment**: The world the agent interacts with\n- **Actions**: Choices available to the agent\n- **Rewards**: Feedback from the environment\n- **Policy**: Strategy for choosing actions\n\n### Famous Applications:\n- Game playing (AlphaGo, OpenAI Five)\n- Robotics control\n- Trading algorithms\n- Resource allocation",
|
| 131 |
-
"category": "Learning Paradigm",
|
| 132 |
-
"color": "#f1f8e9"
|
| 133 |
-
},
|
| 134 |
-
{
|
| 135 |
-
"position": [169, 190],
|
| 136 |
-
"title": "Machine Learning (Position)",
|
| 137 |
-
"content": "This **machine learning** instance is highlighted using position-based highlighting at characters 169-190.\n\n### Position Highlighting Use Cases:\n- Academic paper annotations\n- Legal document markup\n- Code documentation\n- Precise text analysis\n\nPosition-based highlighting ensures exact text selection without ambiguity.",
|
| 138 |
-
"category": "Position Demo",
|
| 139 |
-
"color": "#e8eaf6"
|
| 140 |
-
}
|
| 141 |
-
]
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 145 |
gr.Markdown("# MarkdownLabel Component Demo")
|
| 146 |
-
gr.Markdown("This demo showcases the MarkdownLabel component with **both term-based and position-based** interactive highlighting and detailed side panel.")
|
| 147 |
-
|
| 148 |
-
gr.Markdown("Includes both term-based (e.g., 'artificial intelligence') and position-based highlighting (yellow highlights).")
|
| 149 |
-
MarkdownLabel(
|
| 150 |
-
value=example_data,
|
| 151 |
-
label="AI Research Report - Mixed Highlighting",
|
| 152 |
-
show_side_panel=True,
|
| 153 |
-
panel_width="350px",
|
| 154 |
-
interactive=True
|
| 155 |
-
)
|
| 156 |
|
| 157 |
# Simple position-based example
|
| 158 |
-
|
| 159 |
-
"markdown_content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
"highlights": [
|
| 161 |
{
|
| 162 |
-
"position": [
|
| 163 |
-
"title": "Quick
|
| 164 |
-
"content": "Highlighted using exact character positions
|
| 165 |
"category": "Position Demo",
|
| 166 |
"color": "#ffeb3b"
|
| 167 |
},
|
| 168 |
{
|
| 169 |
"term": "brown fox",
|
| 170 |
"title": "Brown Fox (Term Match)",
|
| 171 |
-
"content": "Highlighted using term matching.",
|
| 172 |
"category": "Term Demo",
|
| 173 |
"color": "#e3f2fd"
|
| 174 |
},
|
| 175 |
{
|
| 176 |
-
"position": [
|
| 177 |
-
"title": "
|
| 178 |
-
"content": "
|
| 179 |
"category": "Position Demo",
|
| 180 |
-
"color": "#
|
| 181 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
]
|
| 183 |
}
|
| 184 |
|
| 185 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 186 |
-
gr.Markdown("This example shows the difference between position-based (yellow
|
| 187 |
MarkdownLabel(
|
| 188 |
-
value=
|
| 189 |
label="Simple Position vs Term Example",
|
| 190 |
show_side_panel=True,
|
| 191 |
panel_width="300px",
|
|
|
|
| 42 |
import gradio as gr
|
| 43 |
from gradio_markdownlabel import MarkdownLabel
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 46 |
gr.Markdown("# MarkdownLabel Component Demo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Simple position-based example
|
| 49 |
+
example = {
|
| 50 |
+
"markdown_content": \"\"\"# Comprehensive Markdown Example
|
| 51 |
+
|
| 52 |
+
## Introduction
|
| 53 |
+
*The* quick **brown fox** jumps over the lazy dog. This is a simple quick example with various **formatting** elements.
|
| 54 |
+
|
| 55 |
+
### Lists and Items
|
| 56 |
+
Here are some important points:
|
| 57 |
+
|
| 58 |
+
1. **First item** - This is the primary consideration
|
| 59 |
+
2. *Second item* - Another important point
|
| 60 |
+
3. Third item with `inline code`
|
| 61 |
+
4. Fourth item containing [a link](https://example.com)
|
| 62 |
+
|
| 63 |
+
#### Unordered Lists
|
| 64 |
+
- Bullet point one
|
| 65 |
+
- Bullet point two with **bold text**
|
| 66 |
+
- Final bullet point
|
| 67 |
+
|
| 68 |
+
### Code Block Example
|
| 69 |
+
```python
|
| 70 |
+
def hello_world():
|
| 71 |
+
print("Hello, World!")
|
| 72 |
+
return "success"
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### Tables
|
| 76 |
+
| Column 1 | Column 2 | Column 3 |
|
| 77 |
+
|----------|----------|----------|
|
| 78 |
+
| Cell 1 | Cell 2 | Cell 3 |
|
| 79 |
+
| Data A | Data B | Data C |
|
| 80 |
+
|
| 81 |
+
### Blockquotes
|
| 82 |
+
> This is a blockquote with some **important** information.
|
| 83 |
+
>
|
| 84 |
+
> It can span multiple lines and contain *emphasis*.
|
| 85 |
+
|
| 86 |
+
### Mixed Content
|
| 87 |
+
The document contains various **formatting** options including:
|
| 88 |
+
|
| 89 |
+
- *Italicized text* for emphasis
|
| 90 |
+
- **Bold text** for importance
|
| 91 |
+
- `Inline code` for technical terms
|
| 92 |
+
- Links like [this one](https://example.com)
|
| 93 |
+
|
| 94 |
+
#### Final Section
|
| 95 |
+
This concludes our comprehensive example with multiple markdown elements for testing position-based highlighting accuracy.\"\"\",
|
| 96 |
"highlights": [
|
| 97 |
{
|
| 98 |
+
"position": [56, 61], # "quick" in "The quick brown fox", note the 2nd quick is not highlighted
|
| 99 |
+
"title": "Quick",
|
| 100 |
+
"content": "Highlighted using exact character positions.",
|
| 101 |
"category": "Position Demo",
|
| 102 |
"color": "#ffeb3b"
|
| 103 |
},
|
| 104 |
{
|
| 105 |
"term": "brown fox",
|
| 106 |
"title": "Brown Fox (Term Match)",
|
| 107 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 108 |
"category": "Term Demo",
|
| 109 |
"color": "#e3f2fd"
|
| 110 |
},
|
| 111 |
{
|
| 112 |
+
"position": [91, 95], # "lazy" in "the lazy dog"
|
| 113 |
+
"title": "Lazy",
|
| 114 |
+
"content": "Position-based highlight",
|
| 115 |
"category": "Position Demo",
|
| 116 |
+
"color": "#ffeb3b"
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"position": [989, 999],
|
| 120 |
+
"title": "Italicized",
|
| 121 |
+
"content": "Highlighting 'Italicized'",
|
| 122 |
+
"category": "Position Demo",
|
| 123 |
+
"color": "#ff9800"
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"term": "formatting",
|
| 127 |
+
"title": "formatting (Term Match)",
|
| 128 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 129 |
+
"category": "Term Demo",
|
| 130 |
+
"color": "#d0167f91"
|
| 131 |
+
},
|
| 132 |
]
|
| 133 |
}
|
| 134 |
|
| 135 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 136 |
+
gr.Markdown("This example shows the difference between position-based (yellow) and term-based (blue) highlighting.")
|
| 137 |
MarkdownLabel(
|
| 138 |
+
value=example,
|
| 139 |
label="Simple Position vs Term Example",
|
| 140 |
show_side_panel=True,
|
| 141 |
panel_width="300px",
|
src/CLAUDE.local.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Here's a concise summary of Gradio custom component development steps for Claude Code's memory:
|
| 2 |
+
|
| 3 |
+
## Gradio Custom Component Development Steps
|
| 4 |
+
|
| 5 |
+
### 1. Setup & Initialization
|
| 6 |
+
- Install Gradio: `pip install gradio`
|
| 7 |
+
- Create component: `gradio cc create MyComponent --template [template_type]`
|
| 8 |
+
- Templates: `HTML`, `File`, `Fallback`, `SimpleTextbox`, `SimpleDropdown`
|
| 9 |
+
|
| 10 |
+
### 2. Project Structure
|
| 11 |
+
```
|
| 12 |
+
MyComponent/
|
| 13 |
+
├── backend/ # Python backend logic
|
| 14 |
+
├── frontend/ # JavaScript/TypeScript frontend
|
| 15 |
+
├── demo/ # Demo app
|
| 16 |
+
└── pyproject.toml # Package configuration
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### 3. Backend Development (`backend/`)
|
| 20 |
+
- Inherit from appropriate Gradio component class
|
| 21 |
+
- Implement `preprocess()` and `postprocess()` methods
|
| 22 |
+
- Define component properties and data types
|
| 23 |
+
- Handle server-side logic
|
| 24 |
+
|
| 25 |
+
### 4. Frontend Development (`frontend/`)
|
| 26 |
+
- Built with Svelte framework
|
| 27 |
+
- Implement component UI in `Index.svelte`
|
| 28 |
+
- Handle user interactions and data flow
|
| 29 |
+
- Style with CSS/Tailwind
|
| 30 |
+
|
| 31 |
+
### 5. Development Workflow
|
| 32 |
+
- `gradio cc dev` - Start development server with hot reload
|
| 33 |
+
- `gradio cc build` - Build component for distribution
|
| 34 |
+
- `gradio cc publish` - Publish to PyPI/Hugging Face Hub
|
| 35 |
+
|
| 36 |
+
### 6. Integration
|
| 37 |
+
- Install: `pip install your-component-name`
|
| 38 |
+
- Import and use in Gradio apps like built-in components
|
| 39 |
+
- Component automatically registers with Gradio
|
| 40 |
+
|
| 41 |
+
### 7. Key Files
|
| 42 |
+
- `backend/mycomponent.py` - Main Python component class
|
| 43 |
+
- `frontend/Index.svelte` - Main frontend component
|
| 44 |
+
- `demo/app.py` - Demo application
|
| 45 |
+
- `pyproject.toml` - Package metadata and dependencies
|
| 46 |
+
|
| 47 |
+
This workflow enables creating reusable, distributable Gradio components with custom functionality.
|
| 48 |
+
|
| 49 |
+
### Python
|
| 50 |
+
|
| 51 |
+
Need to run `run `pip install -e .` for cc dev
|
src/README.md
CHANGED
|
@@ -27,150 +27,100 @@ pip install gradio_markdownlabel
|
|
| 27 |
import gradio as gr
|
| 28 |
from gradio_markdownlabel import MarkdownLabel
|
| 29 |
|
| 30 |
-
# Create a comprehensive example with rich markdown content and multiple highlights
|
| 31 |
-
example_data = {
|
| 32 |
-
"markdown_content": """# AI and Machine Learning Research Report
|
| 33 |
-
|
| 34 |
-
## Introduction
|
| 35 |
-
|
| 36 |
-
This document explores the rapidly evolving field of **artificial intelligence** and its various applications in modern technology. The study focuses on *machine learning* techniques and their impact on different industries.
|
| 37 |
-
|
| 38 |
-
## Key Technologies
|
| 39 |
-
|
| 40 |
-
### Deep Learning
|
| 41 |
-
*Deep learning* represents a subset of machine learning that uses **neural networks** with multiple layers. This approach has revolutionized areas such as:
|
| 42 |
-
|
| 43 |
-
- Computer vision
|
| 44 |
-
- Natural language processing
|
| 45 |
-
- Speech recognition
|
| 46 |
-
|
| 47 |
-
### Natural Language Processing
|
| 48 |
-
**Natural language processing** (NLP) enables computers to understand and interpret human language. Key applications include:
|
| 49 |
-
|
| 50 |
-
1. Text analysis
|
| 51 |
-
2. Sentiment analysis
|
| 52 |
-
3. Language translation
|
| 53 |
-
|
| 54 |
-
## Applications
|
| 55 |
-
|
| 56 |
-
The integration of **computer vision** in autonomous vehicles has transformed the automotive industry. Similarly, **reinforcement learning** has shown remarkable success in gaming and robotics.
|
| 57 |
-
|
| 58 |
-
## Conclusion
|
| 59 |
-
|
| 60 |
-
As **artificial intelligence** continues to advance, we expect to see more sophisticated applications of these technologies across various domains.
|
| 61 |
-
""",
|
| 62 |
-
"highlights": [
|
| 63 |
-
{
|
| 64 |
-
"term": "artificial intelligence",
|
| 65 |
-
"title": "Artificial Intelligence (AI)",
|
| 66 |
-
"content": "**Artificial Intelligence** refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. AI systems can perform tasks that typically require human intelligence, such as:\n\n- Visual perception\n- Speech recognition\n- Decision-making\n- Language translation\n\nAI is broadly categorized into:\n1. **Narrow AI** - designed for specific tasks\n2. **General AI** - hypothetical AI with human-level cognitive abilities",
|
| 67 |
-
"category": "Core Technology",
|
| 68 |
-
"color": "#e3f2fd"
|
| 69 |
-
},
|
| 70 |
-
{
|
| 71 |
-
"term": "machine learning",
|
| 72 |
-
"title": "Machine Learning (ML)",
|
| 73 |
-
"content": "**Machine Learning** is a subset of AI that focuses on the development of algorithms that can learn and improve from experience without being explicitly programmed.\n\n### Types of Machine Learning:\n- **Supervised Learning**: Learning with labeled examples\n- **Unsupervised Learning**: Finding patterns in unlabeled data\n- **Reinforcement Learning**: Learning through interaction with environment\n\n### Applications:\n- Recommendation systems\n- Fraud detection\n- Medical diagnosis\n- Autonomous vehicles",
|
| 74 |
-
"category": "Core Technology",
|
| 75 |
-
"color": "#f3e5f5"
|
| 76 |
-
},
|
| 77 |
-
{
|
| 78 |
-
"term": "deep learning",
|
| 79 |
-
"title": "Deep Learning",
|
| 80 |
-
"content": "**Deep Learning** is a specialized subset of machine learning that uses artificial neural networks with multiple layers (deep neural networks) to model and understand complex patterns.\n\n### Key Characteristics:\n- Multiple hidden layers\n- Automatic feature extraction\n- Hierarchical learning\n\n### Popular Architectures:\n- Convolutional Neural Networks (CNNs)\n- Recurrent Neural Networks (RNNs)\n- Transformers\n\n### Applications:\n- Image recognition\n- Natural language processing\n- Speech synthesis",
|
| 81 |
-
"category": "Advanced Technique",
|
| 82 |
-
"color": "#e8f5e8"
|
| 83 |
-
},
|
| 84 |
-
{
|
| 85 |
-
"term": "neural networks",
|
| 86 |
-
"title": "Neural Networks",
|
| 87 |
-
"content": "**Neural Networks** are computing systems inspired by biological neural networks. They consist of interconnected nodes (neurons) that process information.\n\n### Components:\n- **Input Layer**: Receives data\n- **Hidden Layers**: Process information\n- **Output Layer**: Produces results\n\n### Types:\n- Feedforward networks\n- Recurrent networks\n- Convolutional networks\n\nNeural networks learn by adjusting the weights of connections between neurons based on training data.",
|
| 88 |
-
"category": "Architecture",
|
| 89 |
-
"color": "#fff3e0"
|
| 90 |
-
},
|
| 91 |
-
{
|
| 92 |
-
"term": "natural language processing",
|
| 93 |
-
"title": "Natural Language Processing (NLP)",
|
| 94 |
-
"content": "**Natural Language Processing** combines computational linguistics with machine learning to enable computers to understand, interpret, and generate human language.\n\n### Core Tasks:\n- **Tokenization**: Breaking text into words/sentences\n- **Part-of-speech tagging**: Identifying grammatical roles\n- **Named entity recognition**: Identifying people, places, organizations\n- **Sentiment analysis**: Determining emotional tone\n\n### Modern Approaches:\n- Transformer models (BERT, GPT)\n- Attention mechanisms\n- Pre-trained language models",
|
| 95 |
-
"category": "Application Domain",
|
| 96 |
-
"color": "#fce4ec"
|
| 97 |
-
},
|
| 98 |
-
{
|
| 99 |
-
"position": [615, 632],
|
| 100 |
-
"title": "Computer Vision (Position-based)",
|
| 101 |
-
"content": "**Computer Vision** highlighted by character position rather than term matching. This demonstrates precise control over highlighting specific text segments.\n\n### Position-based Benefits:\n- Exact character-level precision\n- No ambiguity with similar terms\n- Works with any text, including special characters\n- Useful for pre-processed documents",
|
| 102 |
-
"category": "Position Highlight",
|
| 103 |
-
"color": "#ffeb3b"
|
| 104 |
-
},
|
| 105 |
-
{
|
| 106 |
-
"term": "computer vision",
|
| 107 |
-
"title": "Computer Vision",
|
| 108 |
-
"content": "**Computer Vision** is a field of AI that enables machines to interpret and understand visual information from the world, mimicking human vision capabilities.\n\n### Key Tasks:\n- **Object Detection**: Locating objects in images\n- **Image Classification**: Categorizing images\n- **Semantic Segmentation**: Pixel-level understanding\n- **Face Recognition**: Identifying individuals\n\n### Applications:\n- Autonomous vehicles\n- Medical imaging\n- Security systems\n- Augmented reality",
|
| 109 |
-
"category": "Application Domain",
|
| 110 |
-
"color": "#e1f5fe"
|
| 111 |
-
},
|
| 112 |
-
{
|
| 113 |
-
"term": "reinforcement learning",
|
| 114 |
-
"title": "Reinforcement Learning (RL)",
|
| 115 |
-
"content": "**Reinforcement Learning** is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize cumulative reward.\n\n### Key Concepts:\n- **Agent**: The learner/decision maker\n- **Environment**: The world the agent interacts with\n- **Actions**: Choices available to the agent\n- **Rewards**: Feedback from the environment\n- **Policy**: Strategy for choosing actions\n\n### Famous Applications:\n- Game playing (AlphaGo, OpenAI Five)\n- Robotics control\n- Trading algorithms\n- Resource allocation",
|
| 116 |
-
"category": "Learning Paradigm",
|
| 117 |
-
"color": "#f1f8e9"
|
| 118 |
-
},
|
| 119 |
-
{
|
| 120 |
-
"position": [169, 190],
|
| 121 |
-
"title": "Machine Learning (Position)",
|
| 122 |
-
"content": "This **machine learning** instance is highlighted using position-based highlighting at characters 169-190.\n\n### Position Highlighting Use Cases:\n- Academic paper annotations\n- Legal document markup\n- Code documentation\n- Precise text analysis\n\nPosition-based highlighting ensures exact text selection without ambiguity.",
|
| 123 |
-
"category": "Position Demo",
|
| 124 |
-
"color": "#e8eaf6"
|
| 125 |
-
}
|
| 126 |
-
]
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 130 |
gr.Markdown("# MarkdownLabel Component Demo")
|
| 131 |
-
gr.Markdown("This demo showcases the MarkdownLabel component with **both term-based and position-based** interactive highlighting and detailed side panel.")
|
| 132 |
-
|
| 133 |
-
gr.Markdown("Includes both term-based (e.g., 'artificial intelligence') and position-based highlighting (yellow highlights).")
|
| 134 |
-
MarkdownLabel(
|
| 135 |
-
value=example_data,
|
| 136 |
-
label="AI Research Report - Mixed Highlighting",
|
| 137 |
-
show_side_panel=True,
|
| 138 |
-
panel_width="350px",
|
| 139 |
-
interactive=True
|
| 140 |
-
)
|
| 141 |
|
| 142 |
# Simple position-based example
|
| 143 |
-
|
| 144 |
-
"markdown_content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
"highlights": [
|
| 146 |
{
|
| 147 |
-
"position": [
|
| 148 |
-
"title": "Quick
|
| 149 |
-
"content": "Highlighted using exact character positions
|
| 150 |
"category": "Position Demo",
|
| 151 |
"color": "#ffeb3b"
|
| 152 |
},
|
| 153 |
{
|
| 154 |
"term": "brown fox",
|
| 155 |
"title": "Brown Fox (Term Match)",
|
| 156 |
-
"content": "Highlighted using term matching.",
|
| 157 |
"category": "Term Demo",
|
| 158 |
"color": "#e3f2fd"
|
| 159 |
},
|
| 160 |
{
|
| 161 |
-
"position": [
|
| 162 |
-
"title": "
|
| 163 |
-
"content": "
|
| 164 |
"category": "Position Demo",
|
| 165 |
-
"color": "#
|
| 166 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
]
|
| 168 |
}
|
| 169 |
|
| 170 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 171 |
-
gr.Markdown("This example shows the difference between position-based (yellow
|
| 172 |
MarkdownLabel(
|
| 173 |
-
value=
|
| 174 |
label="Simple Position vs Term Example",
|
| 175 |
show_side_panel=True,
|
| 176 |
panel_width="300px",
|
|
|
|
| 27 |
import gradio as gr
|
| 28 |
from gradio_markdownlabel import MarkdownLabel
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 31 |
gr.Markdown("# MarkdownLabel Component Demo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Simple position-based example
|
| 34 |
+
example = {
|
| 35 |
+
"markdown_content": """# Comprehensive Markdown Example
|
| 36 |
+
|
| 37 |
+
## Introduction
|
| 38 |
+
*The* quick **brown fox** jumps over the lazy dog. This is a simple quick example with various **formatting** elements.
|
| 39 |
+
|
| 40 |
+
### Lists and Items
|
| 41 |
+
Here are some important points:
|
| 42 |
+
|
| 43 |
+
1. **First item** - This is the primary consideration
|
| 44 |
+
2. *Second item* - Another important point
|
| 45 |
+
3. Third item with `inline code`
|
| 46 |
+
4. Fourth item containing [a link](https://example.com)
|
| 47 |
+
|
| 48 |
+
#### Unordered Lists
|
| 49 |
+
- Bullet point one
|
| 50 |
+
- Bullet point two with **bold text**
|
| 51 |
+
- Final bullet point
|
| 52 |
+
|
| 53 |
+
### Code Block Example
|
| 54 |
+
```python
|
| 55 |
+
def hello_world():
|
| 56 |
+
print("Hello, World!")
|
| 57 |
+
return "success"
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### Tables
|
| 61 |
+
| Column 1 | Column 2 | Column 3 |
|
| 62 |
+
|----------|----------|----------|
|
| 63 |
+
| Cell 1 | Cell 2 | Cell 3 |
|
| 64 |
+
| Data A | Data B | Data C |
|
| 65 |
+
|
| 66 |
+
### Blockquotes
|
| 67 |
+
> This is a blockquote with some **important** information.
|
| 68 |
+
>
|
| 69 |
+
> It can span multiple lines and contain *emphasis*.
|
| 70 |
+
|
| 71 |
+
### Mixed Content
|
| 72 |
+
The document contains various **formatting** options including:
|
| 73 |
+
|
| 74 |
+
- *Italicized text* for emphasis
|
| 75 |
+
- **Bold text** for importance
|
| 76 |
+
- `Inline code` for technical terms
|
| 77 |
+
- Links like [this one](https://example.com)
|
| 78 |
+
|
| 79 |
+
#### Final Section
|
| 80 |
+
This concludes our comprehensive example with multiple markdown elements for testing position-based highlighting accuracy.""",
|
| 81 |
"highlights": [
|
| 82 |
{
|
| 83 |
+
"position": [56, 61], # "quick" in "The quick brown fox", note the 2nd quick is not highlighted
|
| 84 |
+
"title": "Quick",
|
| 85 |
+
"content": "Highlighted using exact character positions.",
|
| 86 |
"category": "Position Demo",
|
| 87 |
"color": "#ffeb3b"
|
| 88 |
},
|
| 89 |
{
|
| 90 |
"term": "brown fox",
|
| 91 |
"title": "Brown Fox (Term Match)",
|
| 92 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 93 |
"category": "Term Demo",
|
| 94 |
"color": "#e3f2fd"
|
| 95 |
},
|
| 96 |
{
|
| 97 |
+
"position": [91, 95], # "lazy" in "the lazy dog"
|
| 98 |
+
"title": "Lazy",
|
| 99 |
+
"content": "Position-based highlight",
|
| 100 |
"category": "Position Demo",
|
| 101 |
+
"color": "#ffeb3b"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"position": [989, 999],
|
| 105 |
+
"title": "Italicized",
|
| 106 |
+
"content": "Highlighting 'Italicized'",
|
| 107 |
+
"category": "Position Demo",
|
| 108 |
+
"color": "#ff9800"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"term": "formatting",
|
| 112 |
+
"title": "formatting (Term Match)",
|
| 113 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 114 |
+
"category": "Term Demo",
|
| 115 |
+
"color": "#d0167f91"
|
| 116 |
+
},
|
| 117 |
]
|
| 118 |
}
|
| 119 |
|
| 120 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 121 |
+
gr.Markdown("This example shows the difference between position-based (yellow) and term-based (blue) highlighting.")
|
| 122 |
MarkdownLabel(
|
| 123 |
+
value=example,
|
| 124 |
label="Simple Position vs Term Example",
|
| 125 |
show_side_panel=True,
|
| 126 |
panel_width="300px",
|
src/backend/gradio_markdownlabel/templates/component/index.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/demo/app.py
CHANGED
|
@@ -2,150 +2,100 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_markdownlabel import MarkdownLabel
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
## Introduction
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
## Key Technologies
|
| 14 |
-
|
| 15 |
-
### Deep Learning
|
| 16 |
-
*Deep learning* represents a subset of machine learning that uses **neural networks** with multiple layers. This approach has revolutionized areas such as:
|
| 17 |
|
| 18 |
-
-
|
| 19 |
-
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
"term": "artificial intelligence",
|
| 40 |
-
"title": "Artificial Intelligence (AI)",
|
| 41 |
-
"content": "**Artificial Intelligence** refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. AI systems can perform tasks that typically require human intelligence, such as:\n\n- Visual perception\n- Speech recognition\n- Decision-making\n- Language translation\n\nAI is broadly categorized into:\n1. **Narrow AI** - designed for specific tasks\n2. **General AI** - hypothetical AI with human-level cognitive abilities",
|
| 42 |
-
"category": "Core Technology",
|
| 43 |
-
"color": "#e3f2fd"
|
| 44 |
-
},
|
| 45 |
-
{
|
| 46 |
-
"term": "machine learning",
|
| 47 |
-
"title": "Machine Learning (ML)",
|
| 48 |
-
"content": "**Machine Learning** is a subset of AI that focuses on the development of algorithms that can learn and improve from experience without being explicitly programmed.\n\n### Types of Machine Learning:\n- **Supervised Learning**: Learning with labeled examples\n- **Unsupervised Learning**: Finding patterns in unlabeled data\n- **Reinforcement Learning**: Learning through interaction with environment\n\n### Applications:\n- Recommendation systems\n- Fraud detection\n- Medical diagnosis\n- Autonomous vehicles",
|
| 49 |
-
"category": "Core Technology",
|
| 50 |
-
"color": "#f3e5f5"
|
| 51 |
-
},
|
| 52 |
-
{
|
| 53 |
-
"term": "deep learning",
|
| 54 |
-
"title": "Deep Learning",
|
| 55 |
-
"content": "**Deep Learning** is a specialized subset of machine learning that uses artificial neural networks with multiple layers (deep neural networks) to model and understand complex patterns.\n\n### Key Characteristics:\n- Multiple hidden layers\n- Automatic feature extraction\n- Hierarchical learning\n\n### Popular Architectures:\n- Convolutional Neural Networks (CNNs)\n- Recurrent Neural Networks (RNNs)\n- Transformers\n\n### Applications:\n- Image recognition\n- Natural language processing\n- Speech synthesis",
|
| 56 |
-
"category": "Advanced Technique",
|
| 57 |
-
"color": "#e8f5e8"
|
| 58 |
-
},
|
| 59 |
-
{
|
| 60 |
-
"term": "neural networks",
|
| 61 |
-
"title": "Neural Networks",
|
| 62 |
-
"content": "**Neural Networks** are computing systems inspired by biological neural networks. They consist of interconnected nodes (neurons) that process information.\n\n### Components:\n- **Input Layer**: Receives data\n- **Hidden Layers**: Process information\n- **Output Layer**: Produces results\n\n### Types:\n- Feedforward networks\n- Recurrent networks\n- Convolutional networks\n\nNeural networks learn by adjusting the weights of connections between neurons based on training data.",
|
| 63 |
-
"category": "Architecture",
|
| 64 |
-
"color": "#fff3e0"
|
| 65 |
-
},
|
| 66 |
-
{
|
| 67 |
-
"term": "natural language processing",
|
| 68 |
-
"title": "Natural Language Processing (NLP)",
|
| 69 |
-
"content": "**Natural Language Processing** combines computational linguistics with machine learning to enable computers to understand, interpret, and generate human language.\n\n### Core Tasks:\n- **Tokenization**: Breaking text into words/sentences\n- **Part-of-speech tagging**: Identifying grammatical roles\n- **Named entity recognition**: Identifying people, places, organizations\n- **Sentiment analysis**: Determining emotional tone\n\n### Modern Approaches:\n- Transformer models (BERT, GPT)\n- Attention mechanisms\n- Pre-trained language models",
|
| 70 |
-
"category": "Application Domain",
|
| 71 |
-
"color": "#fce4ec"
|
| 72 |
-
},
|
| 73 |
-
{
|
| 74 |
-
"position": [615, 632],
|
| 75 |
-
"title": "Computer Vision (Position-based)",
|
| 76 |
-
"content": "**Computer Vision** highlighted by character position rather than term matching. This demonstrates precise control over highlighting specific text segments.\n\n### Position-based Benefits:\n- Exact character-level precision\n- No ambiguity with similar terms\n- Works with any text, including special characters\n- Useful for pre-processed documents",
|
| 77 |
-
"category": "Position Highlight",
|
| 78 |
-
"color": "#ffeb3b"
|
| 79 |
-
},
|
| 80 |
-
{
|
| 81 |
-
"term": "computer vision",
|
| 82 |
-
"title": "Computer Vision",
|
| 83 |
-
"content": "**Computer Vision** is a field of AI that enables machines to interpret and understand visual information from the world, mimicking human vision capabilities.\n\n### Key Tasks:\n- **Object Detection**: Locating objects in images\n- **Image Classification**: Categorizing images\n- **Semantic Segmentation**: Pixel-level understanding\n- **Face Recognition**: Identifying individuals\n\n### Applications:\n- Autonomous vehicles\n- Medical imaging\n- Security systems\n- Augmented reality",
|
| 84 |
-
"category": "Application Domain",
|
| 85 |
-
"color": "#e1f5fe"
|
| 86 |
-
},
|
| 87 |
-
{
|
| 88 |
-
"term": "reinforcement learning",
|
| 89 |
-
"title": "Reinforcement Learning (RL)",
|
| 90 |
-
"content": "**Reinforcement Learning** is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize cumulative reward.\n\n### Key Concepts:\n- **Agent**: The learner/decision maker\n- **Environment**: The world the agent interacts with\n- **Actions**: Choices available to the agent\n- **Rewards**: Feedback from the environment\n- **Policy**: Strategy for choosing actions\n\n### Famous Applications:\n- Game playing (AlphaGo, OpenAI Five)\n- Robotics control\n- Trading algorithms\n- Resource allocation",
|
| 91 |
-
"category": "Learning Paradigm",
|
| 92 |
-
"color": "#f1f8e9"
|
| 93 |
-
},
|
| 94 |
-
{
|
| 95 |
-
"position": [169, 190],
|
| 96 |
-
"title": "Machine Learning (Position)",
|
| 97 |
-
"content": "This **machine learning** instance is highlighted using position-based highlighting at characters 169-190.\n\n### Position Highlighting Use Cases:\n- Academic paper annotations\n- Legal document markup\n- Code documentation\n- Precise text analysis\n\nPosition-based highlighting ensures exact text selection without ambiguity.",
|
| 98 |
-
"category": "Position Demo",
|
| 99 |
-
"color": "#e8eaf6"
|
| 100 |
-
}
|
| 101 |
-
]
|
| 102 |
-
}
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
gr.Markdown("This demo showcases the MarkdownLabel component with **both term-based and position-based** interactive highlighting and detailed side panel.")
|
| 107 |
-
|
| 108 |
-
gr.Markdown("Includes both term-based (e.g., 'artificial intelligence') and position-based highlighting (yellow highlights).")
|
| 109 |
-
MarkdownLabel(
|
| 110 |
-
value=example_data,
|
| 111 |
-
label="AI Research Report - Mixed Highlighting",
|
| 112 |
-
show_side_panel=True,
|
| 113 |
-
panel_width="350px",
|
| 114 |
-
interactive=True
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
# Simple position-based example
|
| 118 |
-
simple_example = {
|
| 119 |
-
"markdown_content": "The quick **brown fox** jumps over the lazy dog. This is a simple example.",
|
| 120 |
"highlights": [
|
| 121 |
{
|
| 122 |
-
"position": [
|
| 123 |
-
"title": "Quick
|
| 124 |
-
"content": "Highlighted using exact character positions
|
| 125 |
"category": "Position Demo",
|
| 126 |
"color": "#ffeb3b"
|
| 127 |
},
|
| 128 |
{
|
| 129 |
"term": "brown fox",
|
| 130 |
"title": "Brown Fox (Term Match)",
|
| 131 |
-
"content": "Highlighted using term matching.",
|
| 132 |
"category": "Term Demo",
|
| 133 |
"color": "#e3f2fd"
|
| 134 |
},
|
| 135 |
{
|
| 136 |
-
"position": [
|
| 137 |
-
"title": "
|
| 138 |
-
"content": "
|
| 139 |
"category": "Position Demo",
|
| 140 |
-
"color": "#
|
| 141 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
]
|
| 143 |
}
|
| 144 |
|
| 145 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 146 |
-
gr.Markdown("This example shows the difference between position-based (yellow
|
| 147 |
MarkdownLabel(
|
| 148 |
-
value=
|
| 149 |
label="Simple Position vs Term Example",
|
| 150 |
show_side_panel=True,
|
| 151 |
panel_width="300px",
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_markdownlabel import MarkdownLabel
|
| 4 |
|
| 5 |
+
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 6 |
+
gr.Markdown("# MarkdownLabel Component Demo")
|
| 7 |
+
|
| 8 |
+
# Simple position-based example
|
| 9 |
+
example = {
|
| 10 |
+
"markdown_content": """# Comprehensive Markdown Example
|
| 11 |
|
| 12 |
## Introduction
|
| 13 |
+
*The* quick **brown fox** jumps over the lazy dog. This is a simple quick example with various **formatting** elements.
|
| 14 |
|
| 15 |
+
### Lists and Items
|
| 16 |
+
Here are some important points:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
1. **First item** - This is the primary consideration
|
| 19 |
+
2. *Second item* - Another important point
|
| 20 |
+
3. Third item with `inline code`
|
| 21 |
+
4. Fourth item containing [a link](https://example.com)
|
| 22 |
|
| 23 |
+
#### Unordered Lists
|
| 24 |
+
- Bullet point one
|
| 25 |
+
- Bullet point two with **bold text**
|
| 26 |
+
- Final bullet point
|
| 27 |
|
| 28 |
+
### Code Block Example
|
| 29 |
+
```python
|
| 30 |
+
def hello_world():
|
| 31 |
+
print("Hello, World!")
|
| 32 |
+
return "success"
|
| 33 |
+
```
|
| 34 |
|
| 35 |
+
### Tables
|
| 36 |
+
| Column 1 | Column 2 | Column 3 |
|
| 37 |
+
|----------|----------|----------|
|
| 38 |
+
| Cell 1 | Cell 2 | Cell 3 |
|
| 39 |
+
| Data A | Data B | Data C |
|
| 40 |
|
| 41 |
+
### Blockquotes
|
| 42 |
+
> This is a blockquote with some **important** information.
|
| 43 |
+
>
|
| 44 |
+
> It can span multiple lines and contain *emphasis*.
|
| 45 |
|
| 46 |
+
### Mixed Content
|
| 47 |
+
The document contains various **formatting** options including:
|
| 48 |
|
| 49 |
+
- *Italicized text* for emphasis
|
| 50 |
+
- **Bold text** for importance
|
| 51 |
+
- `Inline code` for technical terms
|
| 52 |
+
- Links like [this one](https://example.com)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
#### Final Section
|
| 55 |
+
This concludes our comprehensive example with multiple markdown elements for testing position-based highlighting accuracy.""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
"highlights": [
|
| 57 |
{
|
| 58 |
+
"position": [56, 61], # "quick" in "The quick brown fox", note the 2nd quick is not highlighted
|
| 59 |
+
"title": "Quick",
|
| 60 |
+
"content": "Highlighted using exact character positions.",
|
| 61 |
"category": "Position Demo",
|
| 62 |
"color": "#ffeb3b"
|
| 63 |
},
|
| 64 |
{
|
| 65 |
"term": "brown fox",
|
| 66 |
"title": "Brown Fox (Term Match)",
|
| 67 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 68 |
"category": "Term Demo",
|
| 69 |
"color": "#e3f2fd"
|
| 70 |
},
|
| 71 |
{
|
| 72 |
+
"position": [91, 95], # "lazy" in "the lazy dog"
|
| 73 |
+
"title": "Lazy",
|
| 74 |
+
"content": "Position-based highlight",
|
| 75 |
"category": "Position Demo",
|
| 76 |
+
"color": "#ffeb3b"
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
"position": [989, 999],
|
| 80 |
+
"title": "Italicized",
|
| 81 |
+
"content": "Highlighting 'Italicized'",
|
| 82 |
+
"category": "Position Demo",
|
| 83 |
+
"color": "#ff9800"
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"term": "formatting",
|
| 87 |
+
"title": "formatting (Term Match)",
|
| 88 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 89 |
+
"category": "Term Demo",
|
| 90 |
+
"color": "#d0167f91"
|
| 91 |
+
},
|
| 92 |
]
|
| 93 |
}
|
| 94 |
|
| 95 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 96 |
+
gr.Markdown("This example shows the difference between position-based (yellow) and term-based (blue) highlighting.")
|
| 97 |
MarkdownLabel(
|
| 98 |
+
value=example,
|
| 99 |
label="Simple Position vs Term Example",
|
| 100 |
show_side_panel=True,
|
| 101 |
panel_width="300px",
|
src/demo/space.py
CHANGED
|
@@ -42,150 +42,100 @@ pip install gradio_markdownlabel
|
|
| 42 |
import gradio as gr
|
| 43 |
from gradio_markdownlabel import MarkdownLabel
|
| 44 |
|
| 45 |
-
# Create a comprehensive example with rich markdown content and multiple highlights
|
| 46 |
-
example_data = {
|
| 47 |
-
"markdown_content": \"\"\"# AI and Machine Learning Research Report
|
| 48 |
-
|
| 49 |
-
## Introduction
|
| 50 |
-
|
| 51 |
-
This document explores the rapidly evolving field of **artificial intelligence** and its various applications in modern technology. The study focuses on *machine learning* techniques and their impact on different industries.
|
| 52 |
-
|
| 53 |
-
## Key Technologies
|
| 54 |
-
|
| 55 |
-
### Deep Learning
|
| 56 |
-
*Deep learning* represents a subset of machine learning that uses **neural networks** with multiple layers. This approach has revolutionized areas such as:
|
| 57 |
-
|
| 58 |
-
- Computer vision
|
| 59 |
-
- Natural language processing
|
| 60 |
-
- Speech recognition
|
| 61 |
-
|
| 62 |
-
### Natural Language Processing
|
| 63 |
-
**Natural language processing** (NLP) enables computers to understand and interpret human language. Key applications include:
|
| 64 |
-
|
| 65 |
-
1. Text analysis
|
| 66 |
-
2. Sentiment analysis
|
| 67 |
-
3. Language translation
|
| 68 |
-
|
| 69 |
-
## Applications
|
| 70 |
-
|
| 71 |
-
The integration of **computer vision** in autonomous vehicles has transformed the automotive industry. Similarly, **reinforcement learning** has shown remarkable success in gaming and robotics.
|
| 72 |
-
|
| 73 |
-
## Conclusion
|
| 74 |
-
|
| 75 |
-
As **artificial intelligence** continues to advance, we expect to see more sophisticated applications of these technologies across various domains.
|
| 76 |
-
\"\"\",
|
| 77 |
-
"highlights": [
|
| 78 |
-
{
|
| 79 |
-
"term": "artificial intelligence",
|
| 80 |
-
"title": "Artificial Intelligence (AI)",
|
| 81 |
-
"content": "**Artificial Intelligence** refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. AI systems can perform tasks that typically require human intelligence, such as:\n\n- Visual perception\n- Speech recognition\n- Decision-making\n- Language translation\n\nAI is broadly categorized into:\n1. **Narrow AI** - designed for specific tasks\n2. **General AI** - hypothetical AI with human-level cognitive abilities",
|
| 82 |
-
"category": "Core Technology",
|
| 83 |
-
"color": "#e3f2fd"
|
| 84 |
-
},
|
| 85 |
-
{
|
| 86 |
-
"term": "machine learning",
|
| 87 |
-
"title": "Machine Learning (ML)",
|
| 88 |
-
"content": "**Machine Learning** is a subset of AI that focuses on the development of algorithms that can learn and improve from experience without being explicitly programmed.\n\n### Types of Machine Learning:\n- **Supervised Learning**: Learning with labeled examples\n- **Unsupervised Learning**: Finding patterns in unlabeled data\n- **Reinforcement Learning**: Learning through interaction with environment\n\n### Applications:\n- Recommendation systems\n- Fraud detection\n- Medical diagnosis\n- Autonomous vehicles",
|
| 89 |
-
"category": "Core Technology",
|
| 90 |
-
"color": "#f3e5f5"
|
| 91 |
-
},
|
| 92 |
-
{
|
| 93 |
-
"term": "deep learning",
|
| 94 |
-
"title": "Deep Learning",
|
| 95 |
-
"content": "**Deep Learning** is a specialized subset of machine learning that uses artificial neural networks with multiple layers (deep neural networks) to model and understand complex patterns.\n\n### Key Characteristics:\n- Multiple hidden layers\n- Automatic feature extraction\n- Hierarchical learning\n\n### Popular Architectures:\n- Convolutional Neural Networks (CNNs)\n- Recurrent Neural Networks (RNNs)\n- Transformers\n\n### Applications:\n- Image recognition\n- Natural language processing\n- Speech synthesis",
|
| 96 |
-
"category": "Advanced Technique",
|
| 97 |
-
"color": "#e8f5e8"
|
| 98 |
-
},
|
| 99 |
-
{
|
| 100 |
-
"term": "neural networks",
|
| 101 |
-
"title": "Neural Networks",
|
| 102 |
-
"content": "**Neural Networks** are computing systems inspired by biological neural networks. They consist of interconnected nodes (neurons) that process information.\n\n### Components:\n- **Input Layer**: Receives data\n- **Hidden Layers**: Process information\n- **Output Layer**: Produces results\n\n### Types:\n- Feedforward networks\n- Recurrent networks\n- Convolutional networks\n\nNeural networks learn by adjusting the weights of connections between neurons based on training data.",
|
| 103 |
-
"category": "Architecture",
|
| 104 |
-
"color": "#fff3e0"
|
| 105 |
-
},
|
| 106 |
-
{
|
| 107 |
-
"term": "natural language processing",
|
| 108 |
-
"title": "Natural Language Processing (NLP)",
|
| 109 |
-
"content": "**Natural Language Processing** combines computational linguistics with machine learning to enable computers to understand, interpret, and generate human language.\n\n### Core Tasks:\n- **Tokenization**: Breaking text into words/sentences\n- **Part-of-speech tagging**: Identifying grammatical roles\n- **Named entity recognition**: Identifying people, places, organizations\n- **Sentiment analysis**: Determining emotional tone\n\n### Modern Approaches:\n- Transformer models (BERT, GPT)\n- Attention mechanisms\n- Pre-trained language models",
|
| 110 |
-
"category": "Application Domain",
|
| 111 |
-
"color": "#fce4ec"
|
| 112 |
-
},
|
| 113 |
-
{
|
| 114 |
-
"position": [615, 632],
|
| 115 |
-
"title": "Computer Vision (Position-based)",
|
| 116 |
-
"content": "**Computer Vision** highlighted by character position rather than term matching. This demonstrates precise control over highlighting specific text segments.\n\n### Position-based Benefits:\n- Exact character-level precision\n- No ambiguity with similar terms\n- Works with any text, including special characters\n- Useful for pre-processed documents",
|
| 117 |
-
"category": "Position Highlight",
|
| 118 |
-
"color": "#ffeb3b"
|
| 119 |
-
},
|
| 120 |
-
{
|
| 121 |
-
"term": "computer vision",
|
| 122 |
-
"title": "Computer Vision",
|
| 123 |
-
"content": "**Computer Vision** is a field of AI that enables machines to interpret and understand visual information from the world, mimicking human vision capabilities.\n\n### Key Tasks:\n- **Object Detection**: Locating objects in images\n- **Image Classification**: Categorizing images\n- **Semantic Segmentation**: Pixel-level understanding\n- **Face Recognition**: Identifying individuals\n\n### Applications:\n- Autonomous vehicles\n- Medical imaging\n- Security systems\n- Augmented reality",
|
| 124 |
-
"category": "Application Domain",
|
| 125 |
-
"color": "#e1f5fe"
|
| 126 |
-
},
|
| 127 |
-
{
|
| 128 |
-
"term": "reinforcement learning",
|
| 129 |
-
"title": "Reinforcement Learning (RL)",
|
| 130 |
-
"content": "**Reinforcement Learning** is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize cumulative reward.\n\n### Key Concepts:\n- **Agent**: The learner/decision maker\n- **Environment**: The world the agent interacts with\n- **Actions**: Choices available to the agent\n- **Rewards**: Feedback from the environment\n- **Policy**: Strategy for choosing actions\n\n### Famous Applications:\n- Game playing (AlphaGo, OpenAI Five)\n- Robotics control\n- Trading algorithms\n- Resource allocation",
|
| 131 |
-
"category": "Learning Paradigm",
|
| 132 |
-
"color": "#f1f8e9"
|
| 133 |
-
},
|
| 134 |
-
{
|
| 135 |
-
"position": [169, 190],
|
| 136 |
-
"title": "Machine Learning (Position)",
|
| 137 |
-
"content": "This **machine learning** instance is highlighted using position-based highlighting at characters 169-190.\n\n### Position Highlighting Use Cases:\n- Academic paper annotations\n- Legal document markup\n- Code documentation\n- Precise text analysis\n\nPosition-based highlighting ensures exact text selection without ambiguity.",
|
| 138 |
-
"category": "Position Demo",
|
| 139 |
-
"color": "#e8eaf6"
|
| 140 |
-
}
|
| 141 |
-
]
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 145 |
gr.Markdown("# MarkdownLabel Component Demo")
|
| 146 |
-
gr.Markdown("This demo showcases the MarkdownLabel component with **both term-based and position-based** interactive highlighting and detailed side panel.")
|
| 147 |
-
|
| 148 |
-
gr.Markdown("Includes both term-based (e.g., 'artificial intelligence') and position-based highlighting (yellow highlights).")
|
| 149 |
-
MarkdownLabel(
|
| 150 |
-
value=example_data,
|
| 151 |
-
label="AI Research Report - Mixed Highlighting",
|
| 152 |
-
show_side_panel=True,
|
| 153 |
-
panel_width="350px",
|
| 154 |
-
interactive=True
|
| 155 |
-
)
|
| 156 |
|
| 157 |
# Simple position-based example
|
| 158 |
-
|
| 159 |
-
"markdown_content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
"highlights": [
|
| 161 |
{
|
| 162 |
-
"position": [
|
| 163 |
-
"title": "Quick
|
| 164 |
-
"content": "Highlighted using exact character positions
|
| 165 |
"category": "Position Demo",
|
| 166 |
"color": "#ffeb3b"
|
| 167 |
},
|
| 168 |
{
|
| 169 |
"term": "brown fox",
|
| 170 |
"title": "Brown Fox (Term Match)",
|
| 171 |
-
"content": "Highlighted using term matching.",
|
| 172 |
"category": "Term Demo",
|
| 173 |
"color": "#e3f2fd"
|
| 174 |
},
|
| 175 |
{
|
| 176 |
-
"position": [
|
| 177 |
-
"title": "
|
| 178 |
-
"content": "
|
| 179 |
"category": "Position Demo",
|
| 180 |
-
"color": "#
|
| 181 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
]
|
| 183 |
}
|
| 184 |
|
| 185 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 186 |
-
gr.Markdown("This example shows the difference between position-based (yellow
|
| 187 |
MarkdownLabel(
|
| 188 |
-
value=
|
| 189 |
label="Simple Position vs Term Example",
|
| 190 |
show_side_panel=True,
|
| 191 |
panel_width="300px",
|
|
|
|
| 42 |
import gradio as gr
|
| 43 |
from gradio_markdownlabel import MarkdownLabel
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Blocks(title="Markdown Label Demo") as demo:
|
| 46 |
gr.Markdown("# MarkdownLabel Component Demo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Simple position-based example
|
| 49 |
+
example = {
|
| 50 |
+
"markdown_content": \"\"\"# Comprehensive Markdown Example
|
| 51 |
+
|
| 52 |
+
## Introduction
|
| 53 |
+
*The* quick **brown fox** jumps over the lazy dog. This is a simple quick example with various **formatting** elements.
|
| 54 |
+
|
| 55 |
+
### Lists and Items
|
| 56 |
+
Here are some important points:
|
| 57 |
+
|
| 58 |
+
1. **First item** - This is the primary consideration
|
| 59 |
+
2. *Second item* - Another important point
|
| 60 |
+
3. Third item with `inline code`
|
| 61 |
+
4. Fourth item containing [a link](https://example.com)
|
| 62 |
+
|
| 63 |
+
#### Unordered Lists
|
| 64 |
+
- Bullet point one
|
| 65 |
+
- Bullet point two with **bold text**
|
| 66 |
+
- Final bullet point
|
| 67 |
+
|
| 68 |
+
### Code Block Example
|
| 69 |
+
```python
|
| 70 |
+
def hello_world():
|
| 71 |
+
print("Hello, World!")
|
| 72 |
+
return "success"
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### Tables
|
| 76 |
+
| Column 1 | Column 2 | Column 3 |
|
| 77 |
+
|----------|----------|----------|
|
| 78 |
+
| Cell 1 | Cell 2 | Cell 3 |
|
| 79 |
+
| Data A | Data B | Data C |
|
| 80 |
+
|
| 81 |
+
### Blockquotes
|
| 82 |
+
> This is a blockquote with some **important** information.
|
| 83 |
+
>
|
| 84 |
+
> It can span multiple lines and contain *emphasis*.
|
| 85 |
+
|
| 86 |
+
### Mixed Content
|
| 87 |
+
The document contains various **formatting** options including:
|
| 88 |
+
|
| 89 |
+
- *Italicized text* for emphasis
|
| 90 |
+
- **Bold text** for importance
|
| 91 |
+
- `Inline code` for technical terms
|
| 92 |
+
- Links like [this one](https://example.com)
|
| 93 |
+
|
| 94 |
+
#### Final Section
|
| 95 |
+
This concludes our comprehensive example with multiple markdown elements for testing position-based highlighting accuracy.\"\"\",
|
| 96 |
"highlights": [
|
| 97 |
{
|
| 98 |
+
"position": [56, 61], # "quick" in "The quick brown fox", note the 2nd quick is not highlighted
|
| 99 |
+
"title": "Quick",
|
| 100 |
+
"content": "Highlighted using exact character positions.",
|
| 101 |
"category": "Position Demo",
|
| 102 |
"color": "#ffeb3b"
|
| 103 |
},
|
| 104 |
{
|
| 105 |
"term": "brown fox",
|
| 106 |
"title": "Brown Fox (Term Match)",
|
| 107 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 108 |
"category": "Term Demo",
|
| 109 |
"color": "#e3f2fd"
|
| 110 |
},
|
| 111 |
{
|
| 112 |
+
"position": [91, 95], # "lazy" in "the lazy dog"
|
| 113 |
+
"title": "Lazy",
|
| 114 |
+
"content": "Position-based highlight",
|
| 115 |
"category": "Position Demo",
|
| 116 |
+
"color": "#ffeb3b"
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"position": [989, 999],
|
| 120 |
+
"title": "Italicized",
|
| 121 |
+
"content": "Highlighting 'Italicized'",
|
| 122 |
+
"category": "Position Demo",
|
| 123 |
+
"color": "#ff9800"
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"term": "formatting",
|
| 127 |
+
"title": "formatting (Term Match)",
|
| 128 |
+
"content": "Highlighted using term matching - will match anywhere this term appears.",
|
| 129 |
+
"category": "Term Demo",
|
| 130 |
+
"color": "#d0167f91"
|
| 131 |
+
},
|
| 132 |
]
|
| 133 |
}
|
| 134 |
|
| 135 |
gr.Markdown("## Position vs Term Highlighting Comparison")
|
| 136 |
+
gr.Markdown("This example shows the difference between position-based (yellow) and term-based (blue) highlighting.")
|
| 137 |
MarkdownLabel(
|
| 138 |
+
value=example,
|
| 139 |
label="Simple Position vs Term Example",
|
| 140 |
show_side_panel=True,
|
| 141 |
panel_width="300px",
|
src/frontend/shared/EditableMarkdownRenderer.svelte
CHANGED
|
@@ -59,14 +59,26 @@
|
|
| 59 |
}
|
| 60 |
|
| 61 |
async function processMarkdown(contentToRender: string) {
|
| 62 |
-
// First, parse the markdown to HTML
|
| 63 |
-
let html = await marked(contentToRender);
|
| 64 |
-
|
| 65 |
// Separate position-based and term-based highlights
|
| 66 |
const positionHighlights = highlights.filter(h => h.position && h.position.length === 2);
|
| 67 |
const termHighlights = highlights.filter(h => h.term && h.term.trim());
|
| 68 |
|
| 69 |
-
// Apply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
termHighlights.forEach(highlight => {
|
| 71 |
if (highlight.term && highlight.term.trim()) {
|
| 72 |
const index = highlights.indexOf(highlight);
|
|
@@ -86,38 +98,61 @@
|
|
| 86 |
}
|
| 87 |
});
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
positionHighlights.forEach(highlight => {
|
| 92 |
const [start, end] = highlight.position!;
|
| 93 |
-
if (start >= 0 && end <=
|
| 94 |
-
const targetText =
|
| 95 |
const color = highlight.color || '#e3f2fd';
|
| 96 |
const index = highlights.indexOf(highlight);
|
| 97 |
|
| 98 |
-
|
| 99 |
-
const
|
| 100 |
|
| 101 |
-
//
|
| 102 |
-
const
|
| 103 |
|
| 104 |
-
|
| 105 |
-
// but using the exact text from the position
|
| 106 |
-
html = html.replace(textRegex, (match: string) => {
|
| 107 |
return `<span class="highlight-position"
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
});
|
| 117 |
}
|
| 118 |
});
|
| 119 |
|
| 120 |
-
|
| 121 |
}
|
| 122 |
|
| 123 |
async function processPanelContent() {
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
async function processMarkdown(contentToRender: string) {
|
|
|
|
|
|
|
|
|
|
| 62 |
// Separate position-based and term-based highlights
|
| 63 |
const positionHighlights = highlights.filter(h => h.position && h.position.length === 2);
|
| 64 |
const termHighlights = highlights.filter(h => h.term && h.term.trim());
|
| 65 |
|
| 66 |
+
// Apply position-based highlights first by inserting special markers
|
| 67 |
+
// Note: Only apply position highlights if contentToRender matches original markdown_content
|
| 68 |
+
let processedMarkdown = contentToRender;
|
| 69 |
+
if (contentToRender === markdown_content) {
|
| 70 |
+
processedMarkdown = applyPositionMarkers(contentToRender, positionHighlights);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// Then parse the markdown to HTML
|
| 74 |
+
let html = await marked(processedMarkdown);
|
| 75 |
+
|
| 76 |
+
// Replace position markers with actual highlight spans (only if we applied them)
|
| 77 |
+
if (contentToRender === markdown_content) {
|
| 78 |
+
html = replacePositionMarkers(html, positionHighlights);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Apply term-based highlights to the HTML
|
| 82 |
termHighlights.forEach(highlight => {
|
| 83 |
if (highlight.term && highlight.term.trim()) {
|
| 84 |
const index = highlights.indexOf(highlight);
|
|
|
|
| 98 |
}
|
| 99 |
});
|
| 100 |
|
| 101 |
+
processedHtml = html;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
function applyPositionMarkers(content: string, positionHighlights: typeof highlights): string {
|
| 105 |
+
// Sort highlights by start position in descending order to avoid position shifts
|
| 106 |
+
const sortedHighlights = [...positionHighlights].sort((a, b) => (b.position![0] - a.position![0]));
|
| 107 |
+
|
| 108 |
+
let result = content;
|
| 109 |
+
|
| 110 |
+
sortedHighlights.forEach(highlight => {
|
| 111 |
+
const [start, end] = highlight.position!;
|
| 112 |
+
if (start >= 0 && end <= result.length && start < end) {
|
| 113 |
+
const targetText = result.substring(start, end);
|
| 114 |
+
const index = highlights.indexOf(highlight);
|
| 115 |
+
|
| 116 |
+
// Create unique markers that won't interfere with markdown rendering
|
| 117 |
+
const startMarker = `|||POSHL_START_${index}|||`;
|
| 118 |
+
const endMarker = `|||POSHL_END_${index}|||`;
|
| 119 |
+
|
| 120 |
+
result = result.substring(0, start) + startMarker + targetText + endMarker + result.substring(end);
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
return result;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function replacePositionMarkers(html: string, positionHighlights: typeof highlights): string {
|
| 128 |
positionHighlights.forEach(highlight => {
|
| 129 |
const [start, end] = highlight.position!;
|
| 130 |
+
if (start >= 0 && end <= markdown_content.length && start < end) {
|
| 131 |
+
const targetText = markdown_content.substring(start, end);
|
| 132 |
const color = highlight.color || '#e3f2fd';
|
| 133 |
const index = highlights.indexOf(highlight);
|
| 134 |
|
| 135 |
+
const startMarker = `|||POSHL_START_${index}|||`;
|
| 136 |
+
const endMarker = `|||POSHL_END_${index}|||`;
|
| 137 |
|
| 138 |
+
// Find and replace the markers with highlight spans
|
| 139 |
+
const markerRegex = new RegExp(`\\|\\|\\|POSHL_START_${index}\\|\\|\\|(.*?)\\|\\|\\|POSHL_END_${index}\\|\\|\\|`, 'g');
|
| 140 |
|
| 141 |
+
html = html.replace(markerRegex, (match, content) => {
|
|
|
|
|
|
|
| 142 |
return `<span class="highlight-position"
|
| 143 |
+
data-index="${index}"
|
| 144 |
+
data-text="${encodeURIComponent(targetText)}"
|
| 145 |
+
style="background-color: ${color}; cursor: pointer; padding: 2px 4px; border-radius: 3px; transition: all 0.2s;"
|
| 146 |
+
role="button"
|
| 147 |
+
tabindex="0"
|
| 148 |
+
aria-label="Highlighted text: ${targetText.replace(/"/g, '"')}">
|
| 149 |
+
${content}
|
| 150 |
+
</span>`;
|
| 151 |
});
|
| 152 |
}
|
| 153 |
});
|
| 154 |
|
| 155 |
+
return html;
|
| 156 |
}
|
| 157 |
|
| 158 |
async function processPanelContent() {
|
src/frontend/shared/MarkdownRenderer.svelte
CHANGED
|
@@ -38,14 +38,20 @@
|
|
| 38 |
}
|
| 39 |
|
| 40 |
async function processMarkdown() {
|
| 41 |
-
// First, parse the markdown to HTML
|
| 42 |
-
let html = await marked(markdown_content);
|
| 43 |
-
|
| 44 |
// Separate position-based and term-based highlights
|
| 45 |
const positionHighlights = highlights.filter(h => h.position && h.position.length === 2);
|
| 46 |
const termHighlights = highlights.filter(h => h.term && h.term.trim());
|
| 47 |
|
| 48 |
-
// Apply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
termHighlights.forEach(highlight => {
|
| 50 |
if (highlight.term && highlight.term.trim()) {
|
| 51 |
const index = highlights.indexOf(highlight);
|
|
@@ -65,8 +71,33 @@
|
|
| 65 |
}
|
| 66 |
});
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
positionHighlights.forEach(highlight => {
|
| 71 |
const [start, end] = highlight.position!;
|
| 72 |
if (start >= 0 && end <= markdown_content.length && start < end) {
|
|
@@ -74,29 +105,27 @@
|
|
| 74 |
const color = highlight.color || '#e3f2fd';
|
| 75 |
const index = highlights.indexOf(highlight);
|
| 76 |
|
| 77 |
-
|
| 78 |
-
const
|
| 79 |
|
| 80 |
-
//
|
| 81 |
-
const
|
| 82 |
|
| 83 |
-
|
| 84 |
-
// but using the exact text from the position
|
| 85 |
-
html = html.replace(textRegex, (match: string) => {
|
| 86 |
return `<span class="highlight-position"
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
});
|
| 96 |
}
|
| 97 |
});
|
| 98 |
|
| 99 |
-
|
| 100 |
}
|
| 101 |
|
| 102 |
async function processPanelContent() {
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
async function processMarkdown() {
|
|
|
|
|
|
|
|
|
|
| 41 |
// Separate position-based and term-based highlights
|
| 42 |
const positionHighlights = highlights.filter(h => h.position && h.position.length === 2);
|
| 43 |
const termHighlights = highlights.filter(h => h.term && h.term.trim());
|
| 44 |
|
| 45 |
+
// Apply position-based highlights first by inserting special markers
|
| 46 |
+
let processedMarkdown = applyPositionMarkers(markdown_content, positionHighlights);
|
| 47 |
+
|
| 48 |
+
// Then parse the markdown to HTML
|
| 49 |
+
let html = await marked(processedMarkdown);
|
| 50 |
+
|
| 51 |
+
// Replace position markers with actual highlight spans
|
| 52 |
+
html = replacePositionMarkers(html, positionHighlights);
|
| 53 |
+
|
| 54 |
+
// Apply term-based highlights to the HTML
|
| 55 |
termHighlights.forEach(highlight => {
|
| 56 |
if (highlight.term && highlight.term.trim()) {
|
| 57 |
const index = highlights.indexOf(highlight);
|
|
|
|
| 71 |
}
|
| 72 |
});
|
| 73 |
|
| 74 |
+
processedHtml = html;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function applyPositionMarkers(content: string, positionHighlights: typeof highlights): string {
|
| 78 |
+
// Sort highlights by start position in descending order to avoid position shifts
|
| 79 |
+
const sortedHighlights = [...positionHighlights].sort((a, b) => (b.position![0] - a.position![0]));
|
| 80 |
+
|
| 81 |
+
let result = content;
|
| 82 |
+
|
| 83 |
+
sortedHighlights.forEach(highlight => {
|
| 84 |
+
const [start, end] = highlight.position!;
|
| 85 |
+
if (start >= 0 && end <= result.length && start < end) {
|
| 86 |
+
const targetText = result.substring(start, end);
|
| 87 |
+
const index = highlights.indexOf(highlight);
|
| 88 |
+
|
| 89 |
+
// Create unique markers that won't interfere with markdown rendering
|
| 90 |
+
const startMarker = `|||POSHL_START_${index}|||`;
|
| 91 |
+
const endMarker = `|||POSHL_END_${index}|||`;
|
| 92 |
+
|
| 93 |
+
result = result.substring(0, start) + startMarker + targetText + endMarker + result.substring(end);
|
| 94 |
+
}
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
return result;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
function replacePositionMarkers(html: string, positionHighlights: typeof highlights): string {
|
| 101 |
positionHighlights.forEach(highlight => {
|
| 102 |
const [start, end] = highlight.position!;
|
| 103 |
if (start >= 0 && end <= markdown_content.length && start < end) {
|
|
|
|
| 105 |
const color = highlight.color || '#e3f2fd';
|
| 106 |
const index = highlights.indexOf(highlight);
|
| 107 |
|
| 108 |
+
const startMarker = `|||POSHL_START_${index}|||`;
|
| 109 |
+
const endMarker = `|||POSHL_END_${index}|||`;
|
| 110 |
|
| 111 |
+
// Find and replace the markers with highlight spans
|
| 112 |
+
const markerRegex = new RegExp(`\\|\\|\\|POSHL_START_${index}\\|\\|\\|(.*?)\\|\\|\\|POSHL_END_${index}\\|\\|\\|`, 'g');
|
| 113 |
|
| 114 |
+
html = html.replace(markerRegex, (match, content) => {
|
|
|
|
|
|
|
| 115 |
return `<span class="highlight-position"
|
| 116 |
+
data-index="${index}"
|
| 117 |
+
data-text="${encodeURIComponent(targetText)}"
|
| 118 |
+
style="background-color: ${color}; cursor: pointer; padding: 2px 4px; border-radius: 3px; transition: all 0.2s;"
|
| 119 |
+
role="button"
|
| 120 |
+
tabindex="0"
|
| 121 |
+
aria-label="Highlighted text: ${targetText.replace(/"/g, '"')}">
|
| 122 |
+
${content}
|
| 123 |
+
</span>`;
|
| 124 |
});
|
| 125 |
}
|
| 126 |
});
|
| 127 |
|
| 128 |
+
return html;
|
| 129 |
}
|
| 130 |
|
| 131 |
async function processPanelContent() {
|
src/pyproject.toml
CHANGED
|
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
|
|
| 8 |
|
| 9 |
[project]
|
| 10 |
name = "gradio_markdownlabel"
|
| 11 |
-
version = "0.0.
|
| 12 |
description = "Python library for easily interacting with trained machine learning models"
|
| 13 |
readme = "README.md"
|
| 14 |
license = "Apache-2.0"
|
|
|
|
| 8 |
|
| 9 |
[project]
|
| 10 |
name = "gradio_markdownlabel"
|
| 11 |
+
version = "0.0.3"
|
| 12 |
description = "Python library for easily interacting with trained machine learning models"
|
| 13 |
readme = "README.md"
|
| 14 |
license = "Apache-2.0"
|