TheoLvs commited on
Commit
1cc5c16
·
1 Parent(s): 742d1a2

Updated portal

Browse files
Files changed (5) hide show
  1. README.md +61 -1
  2. app.py +113 -74
  3. logo.png +0 -0
  4. modelcard.md +0 -61
  5. sandbox.ipynb +0 -37
README.md CHANGED
@@ -9,4 +9,64 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # Random Baseline Model for Climate Disinformation Classification
13
+
14
+ ## Model Description
15
+
16
+ This is a random baseline model for the Frugal AI Challenge 2024, specifically for the text classification task of identifying climate disinformation. The model serves as a performance floor, randomly assigning labels to text inputs without any learning.
17
+
18
+ ### Intended Use
19
+
20
+ - **Primary intended uses**: Baseline comparison for climate disinformation classification models
21
+ - **Primary intended users**: Researchers and developers participating in the Frugal AI Challenge
22
+ - **Out-of-scope use cases**: Not intended for production use or real-world classification tasks
23
+
24
+ ## Training Data
25
+
26
+ The model uses the QuotaClimat/frugalaichallenge-text-train dataset:
27
+ - Size: ~6000 examples
28
+ - Split: 80% train, 20% test
29
+ - 8 categories of climate disinformation claims
30
+
31
+ ### Labels
32
+ 0. No relevant claim detected
33
+ 1. Global warming is not happening
34
+ 2. Not caused by humans
35
+ 3. Not bad or beneficial
36
+ 4. Solutions harmful/unnecessary
37
+ 5. Science is unreliable
38
+ 6. Proponents are biased
39
+ 7. Fossil fuels are needed
40
+
41
+ ## Performance
42
+
43
+ ### Metrics
44
+ - **Accuracy**: ~12.5% (random chance with 8 classes)
45
+ - **Environmental Impact**:
46
+ - Emissions tracked in gCO2eq
47
+ - Energy consumption tracked in Wh
48
+
49
+ ### Model Architecture
50
+ The model implements a random choice between the 8 possible labels, serving as the simplest possible baseline.
51
+
52
+ ## Environmental Impact
53
+
54
+ Environmental impact is tracked using CodeCarbon, measuring:
55
+ - Carbon emissions during inference
56
+ - Energy consumption during inference
57
+
58
+ This tracking helps establish a baseline for the environmental impact of model deployment and inference.
59
+
60
+ ## Limitations
61
+ - Makes completely random predictions
62
+ - No learning or pattern recognition
63
+ - No consideration of input text
64
+ - Serves only as a baseline reference
65
+ - Not suitable for any real-world applications
66
+
67
+ ## Ethical Considerations
68
+
69
+ - Dataset contains sensitive topics related to climate disinformation
70
+ - Model makes random predictions and should not be used for actual classification
71
+ - Environmental impact is tracked to promote awareness of AI's carbon footprint
72
+ ```
app.py CHANGED
@@ -22,50 +22,47 @@ print(HF_TOKEN)
22
  if not HF_TOKEN:
23
  print("Warning: HF_TOKEN not found in environment variables. Submissions will not work.")
24
 
 
25
  tracker = EmissionsTracker(allow_multiple_runs=True)
26
 
27
- # Function to get space username and URL
28
- def get_space_info():
29
- space_name = os.getenv("SPACE_ID", "")
30
- if space_name:
31
- try:
32
- username = space_name.split("/")[0]
33
- space_url = f"https://huggingface.co/spaces/{space_name}"
34
- return username, space_url
35
- except Exception as e:
36
- print(f"Error getting space info: {e}")
37
- return "local-user", "local-development"
38
-
39
- def clean_emissions_data(emissions_data):
40
- """Remove unwanted fields from emissions data"""
41
- data_dict = emissions_data.__dict__
42
- fields_to_remove = ['timestamp', 'project_name', 'experiment_id', 'latitude', 'longitude']
43
- return {k: v for k, v in data_dict.items() if k not in fields_to_remove}
44
 
45
  @spaces.GPU
46
- def evaluate():
47
  # Get space info
48
  username, space_url = get_space_info()
49
 
50
  # Initialize tracker
51
  tracker.start()
52
  tracker.start_task("inference")
 
 
 
 
 
53
 
54
  # Make random predictions
55
  true_labels = test_dataset["label"]
56
  predictions = [random.randint(0, 7) for _ in range(len(true_labels))]
57
-
 
 
 
 
 
 
 
58
  # Calculate accuracy
59
  accuracy = accuracy_score(true_labels, predictions)
60
 
61
- # Stop tracking emissions
62
- emissions_data = tracker.stop_task()
63
-
64
  # Prepare complete results
65
  results = {
66
  "username": username,
67
  "space_url": space_url,
68
  "submission_timestamp": datetime.now().isoformat(),
 
69
  "accuracy": float(accuracy),
70
  "energy_consumed_wh": emissions_data.energy_consumed * 1000,
71
  "emissions_gco2eq": emissions_data.emissions * 1000,
@@ -80,40 +77,76 @@ def evaluate():
80
  json.dumps(results, indent=2)
81
  ]
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def submit_results(results_json):
84
  if not results_json:
85
  return gr.Warning("No results to submit")
86
 
87
- if not HF_TOKEN:
88
- return gr.Warning("HF_TOKEN not found. Please set up your Hugging Face token.")
 
89
 
90
- # try:
91
- # results_json is already a string, no need to load it
92
- results_str = json.dumps(results_json) # Parse the JSON string to get the data
93
 
94
- # Create a temporary file with the results
95
- with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as f:
96
- # Write the original JSON string to file
97
- f.write(results_str)
98
- temp_path = f.name
99
-
100
- # Upload to the dataset
101
- api = HfApi(token=HF_TOKEN)
102
- path_in_repo = f"submissions/{results_json['username']}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
103
- api.upload_file(
104
- path_or_fileobj=temp_path,
105
- path_in_repo=path_in_repo,
106
- repo_id="frugal-ai-challenge/public-leaderboard-text",
107
- repo_type="dataset",
108
- token=HF_TOKEN
109
- )
110
 
111
- # Clean up
112
- os.unlink(temp_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
- return gr.Info("Results submitted successfully to the leaderboard! 🎉")
115
- # except Exception as e:
116
- # return gr.Warning(f"Error submitting results: {str(e)}")
 
117
 
118
  # Define the label mapping
119
  LABEL_MAPPING = {
@@ -127,18 +160,6 @@ LABEL_MAPPING = {
127
  "7_fossil_fuels_needed": 7 # Fossil fuels are needed
128
  }
129
 
130
- # Reverse mapping for display purposes
131
- LABEL_DESCRIPTIONS = {
132
- 0: "No relevant claim detected",
133
- 1: "Global warming is not happening",
134
- 2: "Not caused by humans",
135
- 3: "Not bad or beneficial",
136
- 4: "Solutions harmful/unnecessary",
137
- 5: "Science is unreliable",
138
- 6: "Proponents are biased",
139
- 7: "Fossil fuels are needed"
140
- }
141
-
142
  # Load and prepare the dataset
143
  print("Loading dataset...")
144
  dataset = load_dataset("QuotaClimat/frugalaichallenge-text-train")
@@ -151,19 +172,17 @@ train_test = dataset["train"].train_test_split(test_size=0.2, seed=42)
151
  train_dataset = train_test["train"]
152
  test_dataset = train_test["test"]
153
 
154
- # Display preview
155
- print("\nFirst 5 rows of test set:")
156
- for i, example in enumerate(test_dataset.select(range(5))):
157
- print(f"\nExample {i+1}:")
158
- print(f"Text: {example['quote'][:100]}...")
159
- print(f"Label: {example['label']} - {LABEL_DESCRIPTIONS[example['label']]}")
160
 
161
  # Create the demo interface
162
  with gr.Blocks() as demo:
163
 
 
164
 
165
  gr.Markdown("""
166
- # Frugal AI Challenge - Text task - Submission portal
167
  ## Climate Disinformation Classification
168
  """)
169
 
@@ -186,10 +205,26 @@ To submit your results, please follow the steps below:
186
  7. Step 1 - Evaluate model: Click on the button to evaluate your model. This will run you model, computes the accuracy on the test set (20% of the train set), and track the energy consumption and emissions.
187
  8. Step 2 - Submit to leaderboard: Click on the button to submit your results to the leaderboard. This will upload the results to the leaderboard dataset and update the leaderboard.
188
  9. You can see the leaderboard at https://huggingface.co/datasets/frugal-ai-challenge/public-leaderboard-text
 
 
 
 
 
 
 
 
 
189
  """)
190
 
191
  with gr.Tab("Model Submission"):
192
- gr.Markdown("## Random Baseline Model")
 
 
 
 
 
 
 
193
 
194
  with gr.Row():
195
  with gr.Column(scale=1):
@@ -199,15 +234,14 @@ To submit your results, please follow the steps below:
199
 
200
  with gr.Row():
201
  accuracy_output = gr.Number(label="Accuracy", precision=4)
202
- emissions_output = gr.Number(label="Emissions (gCO2eq)", precision=12)
203
  energy_output = gr.Number(label="Energy Consumed (Wh)", precision=12)
204
-
205
  with gr.Row():
206
  results_json = gr.JSON(label="Detailed Results", visible=True)
207
 
208
  evaluate_btn.click(
209
  evaluate,
210
- inputs=None,
211
  outputs=[accuracy_output, emissions_output, energy_output, results_json]
212
  )
213
 
@@ -218,9 +252,14 @@ To submit your results, please follow the steps below:
218
  )
219
 
220
  with gr.Tab("Model Card"):
221
- with open("modelcard.md", "r") as f:
222
- model_card_content = f.read()
223
- gr.Markdown(model_card_content)
 
 
 
 
 
224
 
225
  if __name__ == "__main__":
226
  demo.launch()
 
22
  if not HF_TOKEN:
23
  print("Warning: HF_TOKEN not found in environment variables. Submissions will not work.")
24
 
25
+ # Initialize carbon emissions tracker with CodeCarbon
26
  tracker = EmissionsTracker(allow_multiple_runs=True)
27
 
28
+ #--------------------------------------------------------------------------------------------
29
+ # FUNCTION TO UPDATE WITH YOUR MODEL SUBMISSION
30
+ #--------------------------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  @spaces.GPU
33
+ def evaluate(model_description):
34
  # Get space info
35
  username, space_url = get_space_info()
36
 
37
  # Initialize tracker
38
  tracker.start()
39
  tracker.start_task("inference")
40
+
41
+ #--------------------------------------------------------------------------------------------
42
+ # YOUR MODEL INFERENCE CODE HERE
43
+ # Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
44
+ #--------------------------------------------------------------------------------------------
45
 
46
  # Make random predictions
47
  true_labels = test_dataset["label"]
48
  predictions = [random.randint(0, 7) for _ in range(len(true_labels))]
49
+
50
+ #--------------------------------------------------------------------------------------------
51
+ # YOUR MODEL INFERENCE STOPS HERE
52
+ #--------------------------------------------------------------------------------------------
53
+
54
+ # Stop tracking emissions
55
+ emissions_data = tracker.stop_task()
56
+
57
  # Calculate accuracy
58
  accuracy = accuracy_score(true_labels, predictions)
59
 
 
 
 
60
  # Prepare complete results
61
  results = {
62
  "username": username,
63
  "space_url": space_url,
64
  "submission_timestamp": datetime.now().isoformat(),
65
+ "model_description": model_description if model_description else "No description provided",
66
  "accuracy": float(accuracy),
67
  "energy_consumed_wh": emissions_data.energy_consumed * 1000,
68
  "emissions_gco2eq": emissions_data.emissions * 1000,
 
77
  json.dumps(results, indent=2)
78
  ]
79
 
80
+
81
+ #--------------------------------------------------------------------------------------------
82
+ # HELPER FUNCTIONS
83
+ #--------------------------------------------------------------------------------------------
84
+
85
+ # Function to get space username and URL
86
+ def get_space_info():
87
+ space_name = os.getenv("SPACE_ID", "")
88
+ if space_name:
89
+ try:
90
+ username = space_name.split("/")[0]
91
+ space_url = f"https://huggingface.co/spaces/{space_name}"
92
+ return username, space_url
93
+ except Exception as e:
94
+ print(f"Error getting space info: {e}")
95
+ return "local-user", "local-development"
96
+
97
+ def clean_emissions_data(emissions_data):
98
+ """Remove unwanted fields from emissions data"""
99
+ data_dict = emissions_data.__dict__
100
+ fields_to_remove = ['timestamp', 'project_name', 'experiment_id', 'latitude', 'longitude']
101
+ return {k: v for k, v in data_dict.items() if k not in fields_to_remove}
102
+
103
+
104
  def submit_results(results_json):
105
  if not results_json:
106
  return gr.Warning("No results to submit")
107
 
108
+ # Check if we're in a Space or have admin dev rights
109
+ space_name = os.getenv("SPACE_ID")
110
+ is_admin_dev = os.getenv("ADMIN_DEV") == "true"
111
 
112
+ if not space_name and not is_admin_dev:
113
+ message = "You cannot submit your model locally, you need to deploy it as a Hugging Face Space first, and then submit it."
114
+ return gr.Warning(message)
115
 
116
+ if not HF_TOKEN:
117
+ return gr.Warning("HF_TOKEN not found. Please set up your Hugging Face token.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
+ try:
120
+ # results_json is already a dict from gr.JSON
121
+ results_str = json.dumps(results_json)
122
+
123
+ # Create a temporary file with the results
124
+ with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as f:
125
+ f.write(results_str)
126
+ temp_path = f.name
127
+
128
+ # Upload to the dataset
129
+ api = HfApi(token=HF_TOKEN)
130
+ path_in_repo = f"submissions/{results_json['username']}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
131
+ api.upload_file(
132
+ path_or_fileobj=temp_path,
133
+ path_in_repo=path_in_repo,
134
+ repo_id="frugal-ai-challenge/public-leaderboard-text",
135
+ repo_type="dataset",
136
+ token=HF_TOKEN
137
+ )
138
+
139
+ # Clean up
140
+ os.unlink(temp_path)
141
+
142
+ return gr.Info("Results submitted successfully to the leaderboard! 🎉")
143
+ except Exception as e:
144
+ return gr.Warning(f"Error submitting results: {str(e)}")
145
 
146
+
147
+ #--------------------------------------------------------------------------------------------
148
+ # DATASET PREPARATION
149
+ #--------------------------------------------------------------------------------------------
150
 
151
  # Define the label mapping
152
  LABEL_MAPPING = {
 
160
  "7_fossil_fuels_needed": 7 # Fossil fuels are needed
161
  }
162
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  # Load and prepare the dataset
164
  print("Loading dataset...")
165
  dataset = load_dataset("QuotaClimat/frugalaichallenge-text-train")
 
172
  train_dataset = train_test["train"]
173
  test_dataset = train_test["test"]
174
 
175
+ #--------------------------------------------------------------------------------------------
176
+ # GRADIO INTERFACE
177
+ #--------------------------------------------------------------------------------------------
 
 
 
178
 
179
  # Create the demo interface
180
  with gr.Blocks() as demo:
181
 
182
+ gr.Image("./logo.png", show_label=False, container=False)
183
 
184
  gr.Markdown("""
185
+ # 📜 Frugal AI Challenge - Text task - Submission portal
186
  ## Climate Disinformation Classification
187
  """)
188
 
 
205
  7. Step 1 - Evaluate model: Click on the button to evaluate your model. This will run you model, computes the accuracy on the test set (20% of the train set), and track the energy consumption and emissions.
206
  8. Step 2 - Submit to leaderboard: Click on the button to submit your results to the leaderboard. This will upload the results to the leaderboard dataset and update the leaderboard.
207
  9. You can see the leaderboard at https://huggingface.co/datasets/frugal-ai-challenge/public-leaderboard-text
208
+
209
+ ## About
210
+ > You can find more information about the Frugal AI Challenge 2025 on the [Frugal AI Challenge website](https://frugal-ai-challenge.org/).
211
+ > Or directly on the organization page on Hugging Face: [Frugal AI Challenge](https://huggingface.co/frugal-ai-challenge)
212
+
213
+ This portal is a submission portal for the Frugal AI Challenge 2025. It is a simple interface to evaluate and submit your model to the leaderboard.
214
+ The challenge is organized by Hugging Face, Data For Good, and the French Ministry of Environment.
215
+
216
+ The goal of the Frugal AI Challenge is to encourage both academic and industry actors to keep efficiency in mind when deploying AI models. By tracking both energy consumption and performance for different AI tasks, we can incentivize frugality in AI deployment while also addressing real-world challenges.
217
  """)
218
 
219
  with gr.Tab("Model Submission"):
220
+
221
+ with gr.Row():
222
+ model_description = gr.Textbox(
223
+ label="Model Description (one sentence)",
224
+ placeholder="Describe your model in one sentence...",
225
+ value="Random baseline",
226
+ lines=2
227
+ )
228
 
229
  with gr.Row():
230
  with gr.Column(scale=1):
 
234
 
235
  with gr.Row():
236
  accuracy_output = gr.Number(label="Accuracy", precision=4)
 
237
  energy_output = gr.Number(label="Energy Consumed (Wh)", precision=12)
238
+ emissions_output = gr.Number(label="Emissions (gCO2eq)", precision=12)
239
  with gr.Row():
240
  results_json = gr.JSON(label="Detailed Results", visible=True)
241
 
242
  evaluate_btn.click(
243
  evaluate,
244
+ inputs=[model_description],
245
  outputs=[accuracy_output, emissions_output, energy_output, results_json]
246
  )
247
 
 
252
  )
253
 
254
  with gr.Tab("Model Card"):
255
+ with open("README.md", "r") as f:
256
+ content = f.read()
257
+ # Remove the YAML header (content between --- markers)
258
+ if content.startswith("---"):
259
+ second_marker = content.find("---", 3)
260
+ if second_marker != -1:
261
+ content = content[second_marker + 3:].strip()
262
+ gr.Markdown(content)
263
 
264
  if __name__ == "__main__":
265
  demo.launch()
logo.png ADDED
modelcard.md DELETED
@@ -1,61 +0,0 @@
1
- # Random Baseline Model Card
2
-
3
- ## Model Description
4
-
5
- **Model Type:** Random Baseline Classifier
6
- **Task:** Climate Change Disinformation Classification
7
- **Version:** 1.0.0
8
- **Last Updated:** 2024
9
-
10
- ### Overview
11
- This is a random baseline model for climate change disinformation classification. It randomly assigns labels to text inputs, serving as a baseline for comparing more sophisticated models.
12
-
13
- ### Intended Use
14
- - **Primary Use:** Baseline comparison for climate disinformation classification models
15
- - **Intended Users:** Researchers and developers working on climate disinformation detection
16
- - **Out-of-Scope Uses:** Not intended for production or real-world classification tasks
17
-
18
- ## Training Data
19
-
20
- **Dataset:** QuotaClimat/frugalaichallenge-text-train
21
- - Size: ~6000 examples
22
- - Split: 80% train, 20% test
23
- - Labels: 8 categories of climate disinformation claims
24
-
25
- ### Labels
26
- 0. No relevant claim detected
27
- 1. Global warming is not happening
28
- 2. Not caused by humans
29
- 3. Not bad or beneficial
30
- 4. Solutions harmful/unnecessary
31
- 5. Science is unreliable
32
- 6. Proponents are biased
33
- 7. Fossil fuels are needed
34
-
35
- ## Performance
36
-
37
- ### Metrics
38
- - **Accuracy:** ~12.5% (random chance)
39
- - **Environmental Impact:**
40
- - Emissions (kgCO2eq)
41
- - Energy Consumed (kWh)
42
-
43
- ### Limitations
44
- - Random predictions with no learning
45
- - No consideration of input text
46
- - Serves only as a baseline reference
47
-
48
- ## Ethical Considerations
49
- - Model makes random predictions and should not be used for actual classification
50
- - Dataset contains sensitive topics related to climate disinformation
51
- - Environmental impact is tracked to promote awareness of AI's carbon footprint
52
-
53
- ## Environmental Impact
54
- This model tracks its environmental impact using CodeCarbon, measuring:
55
- - Carbon emissions
56
- - Energy consumption
57
-
58
- ## Caveats and Recommendations
59
- - Use only as a baseline comparison
60
- - Not suitable for production use
61
- - Consider environmental impact when running experiments
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sandbox.ipynb DELETED
@@ -1,37 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "6941ccb0-6ed0-45c1-9460-8f8c0bbfc288",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "from codecarbon import EmissionsTracker\n",
11
- "tracker = EmissionsTracker()\n",
12
- "tracker.start()"
13
- ]
14
- }
15
- ],
16
- "metadata": {
17
- "kernelspec": {
18
- "display_name": "Python 3 (ipykernel)",
19
- "language": "python",
20
- "name": "python3"
21
- },
22
- "language_info": {
23
- "codemirror_mode": {
24
- "name": "ipython",
25
- "version": 3
26
- },
27
- "file_extension": ".py",
28
- "mimetype": "text/x-python",
29
- "name": "python",
30
- "nbconvert_exporter": "python",
31
- "pygments_lexer": "ipython3",
32
- "version": "3.12.4"
33
- }
34
- },
35
- "nbformat": 4,
36
- "nbformat_minor": 5
37
- }