Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -52,18 +52,12 @@ class AudioEvaluationRequest(BaseEvaluationRequest):
|
|
| 52 |
dataset_name: str = Field("rfcx/frugalai",
|
| 53 |
description="The name of the dataset on HuggingFace Hub")
|
| 54 |
|
| 55 |
-
class
|
| 56 |
name = "evaluate_consumption"
|
| 57 |
-
description = "
|
| 58 |
-
inputs = {
|
| 59 |
-
"code": {
|
| 60 |
-
"type": "string",
|
| 61 |
-
"description": "The code to evaluate."
|
| 62 |
-
}
|
| 63 |
-
}
|
| 64 |
output_type = "string"
|
| 65 |
|
| 66 |
-
def forward(self
|
| 67 |
request = AudioEvaluationRequest()
|
| 68 |
logging.info("Chargement des données")
|
| 69 |
dataset = load_dataset(request.dataset_name, streaming=True, token=os.getenv("HF_TOKEN"))
|
|
@@ -119,4 +113,26 @@ class evaluate_consumption(Tool):
|
|
| 119 |
# Stop tracking emissions
|
| 120 |
emissions_data = tracker.stop_task()
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
return emissions_data
|
|
|
|
| 52 |
dataset_name: str = Field("rfcx/frugalai",
|
| 53 |
description="The name of the dataset on HuggingFace Hub")
|
| 54 |
|
| 55 |
+
class evaluate_consumption_example(Tool):
|
| 56 |
name = "evaluate_consumption"
|
| 57 |
+
description = "This is only an example. If a manager wants to know what you are capable of, use it : it will use code carbon to evaluate the CO2 emissions from an example Python code"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
output_type = "string"
|
| 59 |
|
| 60 |
+
def forward(self):
|
| 61 |
request = AudioEvaluationRequest()
|
| 62 |
logging.info("Chargement des données")
|
| 63 |
dataset = load_dataset(request.dataset_name, streaming=True, token=os.getenv("HF_TOKEN"))
|
|
|
|
| 113 |
# Stop tracking emissions
|
| 114 |
emissions_data = tracker.stop_task()
|
| 115 |
|
| 116 |
+
return emissions_data
|
| 117 |
+
|
| 118 |
+
class evaluate_consumption(Tool):
|
| 119 |
+
name = "evaluate_consumption"
|
| 120 |
+
description = "Uses code carbon to evaluate the CO2 emissions from a given Python code"
|
| 121 |
+
inputs = {
|
| 122 |
+
"code": {
|
| 123 |
+
"type": "string",
|
| 124 |
+
"description": "The code to evaluate."
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
output_type = "string"
|
| 128 |
+
|
| 129 |
+
def forward(self, code):
|
| 130 |
+
|
| 131 |
+
# Start tracking emissions
|
| 132 |
+
tracker.start()
|
| 133 |
+
tracker.start_task("inference")
|
| 134 |
+
exec(code)
|
| 135 |
+
# Stop tracking emissions
|
| 136 |
+
emissions_data = tracker.stop_task()
|
| 137 |
+
|
| 138 |
return emissions_data
|