Spaces:
Runtime error
Runtime error
Commit
·
7c2198c
1
Parent(s):
6f69d86
add folder utils
Browse files
utils/__init__.py
ADDED
|
File without changes
|
utils/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (147 Bytes). View file
|
|
|
utils/__pycache__/emissions.cpython-312.pyc
ADDED
|
Binary file (1.84 kB). View file
|
|
|
utils/__pycache__/evaluation.cpython-312.pyc
ADDED
|
Binary file (1.61 kB). View file
|
|
|
utils/emissions.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from codecarbon import EmissionsTracker
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Initialize tracker
|
| 5 |
+
tracker = EmissionsTracker(allow_multiple_runs=True)
|
| 6 |
+
|
| 7 |
+
class EmissionsData:
|
| 8 |
+
def __init__(self, energy_consumed: float, emissions: float):
|
| 9 |
+
self.energy_consumed = energy_consumed
|
| 10 |
+
self.emissions = emissions
|
| 11 |
+
|
| 12 |
+
def clean_emissions_data(emissions_data):
|
| 13 |
+
"""Remove unwanted fields from emissions data"""
|
| 14 |
+
data_dict = emissions_data.__dict__
|
| 15 |
+
fields_to_remove = ['timestamp', 'project_name', 'experiment_id', 'latitude', 'longitude']
|
| 16 |
+
return {k: v for k, v in data_dict.items() if k not in fields_to_remove}
|
| 17 |
+
|
| 18 |
+
def get_space_info():
|
| 19 |
+
"""Get the space username and URL from environment variables"""
|
| 20 |
+
space_name = os.getenv("SPACE_ID", "")
|
| 21 |
+
if space_name:
|
| 22 |
+
try:
|
| 23 |
+
username = space_name.split("/")[0]
|
| 24 |
+
space_url = f"https://huggingface.co/spaces/{space_name}"
|
| 25 |
+
return username, space_url
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Error getting space info: {e}")
|
| 28 |
+
return "local-user", "local-development"
|
utils/evaluation.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
from pydantic import BaseModel, Field
|
| 3 |
+
|
| 4 |
+
class BaseEvaluationRequest(BaseModel):
|
| 5 |
+
test_size: float = Field(0.2, ge=0.0, le=1.0, description="Size of the test split (between 0 and 1)")
|
| 6 |
+
test_seed: int = Field(42, ge=0, description="Random seed for reproducibility")
|
| 7 |
+
|
| 8 |
+
class TextEvaluationRequest(BaseEvaluationRequest):
|
| 9 |
+
dataset_name: str = Field("QuotaClimat/frugalaichallenge-text-train",
|
| 10 |
+
description="The name of the dataset on HuggingFace Hub")
|
| 11 |
+
|
| 12 |
+
class ImageEvaluationRequest(BaseEvaluationRequest):
|
| 13 |
+
dataset_name: str = Field("pyronear/pyro-sdis",
|
| 14 |
+
description="The name of the dataset on HuggingFace Hub")
|
| 15 |
+
|
| 16 |
+
class AudioEvaluationRequest(BaseEvaluationRequest):
|
| 17 |
+
dataset_name: str = Field("rfcx/frugalai",
|
| 18 |
+
description="The name of the dataset on HuggingFace Hub")
|