Upload tool
Browse files- app.py +6 -0
- requirements.txt +1 -0
- tool.py +26 -0
app.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import launch_gradio_demo
|
2 |
+
from tool import InfoTheoryExplainerTool
|
3 |
+
|
4 |
+
tool = InfoTheoryExplainerTool()
|
5 |
+
|
6 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
smolagents
|
tool.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
|
4 |
+
class InfoTheoryExplainerTool(Tool):
|
5 |
+
name = "information_theory_explainer"
|
6 |
+
description = """
|
7 |
+
Five basic information theory concepts in simple terms.
|
8 |
+
Given a concept name, it returns a high-school explanation with an example if applicable.
|
9 |
+
"""
|
10 |
+
inputs = {'concept': {'type': 'string', 'description': "The information theory concept to explain (e.g., 'entropy', 'mutual information', 'KL divergence')."}}
|
11 |
+
output_type = "string"
|
12 |
+
|
13 |
+
def forward(self, concept: str):
|
14 |
+
explanations = {
|
15 |
+
"entropy": "Entropy measures the uncertainty or unpredictability in a set of outcomes. Example: A fair coin flip has 1 bit of entropy.",
|
16 |
+
"mutual information": "Mutual information quantifies how much information one random variable tells you about another. Example: Knowing the weather can reduce uncertainty about umbrella usage.",
|
17 |
+
"kl divergence": "KL Divergence measures how one probability distribution differs from another. It's not symmetric and often used in model evaluation.",
|
18 |
+
"cross entropy": "Cross-entropy measures the difference between the true distribution and the predicted one, often used as a loss function in classification tasks.",
|
19 |
+
"channel capacity": "Channel capacity is the maximum rate at which information can be reliably transmitted over a communication channel."
|
20 |
+
}
|
21 |
+
|
22 |
+
key = concept.lower().strip()
|
23 |
+
return explanations.get(key, "Concept not found. Try 'entropy', 'mutual information', 'KL divergence', 'cross entropy', or 'channel capacity'.")
|
24 |
+
|
25 |
+
def __init__(self, *args, **kwargs):
|
26 |
+
self.is_initialized = False
|