Spaces:
Paused
Paused
Commit
•
b1335de
1
Parent(s):
54daf6f
replace with foundation category
Browse files- algo.py +4 -4
- app.py +2 -2
- category_mapper.py +1 -1
- db/db_utils.py +4 -4
- mapping_template.py +1 -1
algo.py
CHANGED
@@ -145,7 +145,7 @@ class Algo:
|
|
145 |
'is_food': False,
|
146 |
'food_nonfood_score': 1.0,
|
147 |
'wweia_category': 'Non-Food Item',
|
148 |
-
'
|
149 |
'water_content': None,
|
150 |
'dry_matter_content': None,
|
151 |
'leakage': None
|
@@ -187,7 +187,7 @@ class Algo:
|
|
187 |
'matching_word': 'Heterogeneous Mixture',
|
188 |
'dictionary_word': 'Heterogeneous Mixture',
|
189 |
'wweia_category': 'Heterogeneous Mixture',
|
190 |
-
'
|
191 |
'dry_matter_content': 0.27,
|
192 |
'water_content': 0.73,
|
193 |
'leakage': 0.1
|
@@ -197,7 +197,7 @@ class Algo:
|
|
197 |
'matching_word': most_conservative_mapping['matching_word'],
|
198 |
'dictionary_word': f"{most_conservative_mapping['dictionary_word']} (Lowest DMC)",
|
199 |
'wweia_category': most_conservative_mapping['wweia_category'],
|
200 |
-
'
|
201 |
'dry_matter_content': most_conservative_mapping['dry_matter_content'],
|
202 |
'water_content': most_conservative_mapping['water_content'],
|
203 |
'leakage': most_conservative_mapping['leakage']
|
@@ -283,7 +283,7 @@ class Algo:
|
|
283 |
|
284 |
mapping.update({
|
285 |
'wweia_category': dictionary_result['wweia_category'] if dictionary_result else None,
|
286 |
-
'
|
287 |
'water_content': dictionary_result['water_content'] if dictionary_result else None,
|
288 |
'dry_matter_content': dictionary_result['dry_matter_content'] if dictionary_result else None,
|
289 |
'leakage': dictionary_result['leakage'] if dictionary_result else None,
|
|
|
145 |
'is_food': False,
|
146 |
'food_nonfood_score': 1.0,
|
147 |
'wweia_category': 'Non-Food Item',
|
148 |
+
'foundation_category': 'Non-Food Item',
|
149 |
'water_content': None,
|
150 |
'dry_matter_content': None,
|
151 |
'leakage': None
|
|
|
187 |
'matching_word': 'Heterogeneous Mixture',
|
188 |
'dictionary_word': 'Heterogeneous Mixture',
|
189 |
'wweia_category': 'Heterogeneous Mixture',
|
190 |
+
'foundation_category': 'Heterogeneous Mixture',
|
191 |
'dry_matter_content': 0.27,
|
192 |
'water_content': 0.73,
|
193 |
'leakage': 0.1
|
|
|
197 |
'matching_word': most_conservative_mapping['matching_word'],
|
198 |
'dictionary_word': f"{most_conservative_mapping['dictionary_word']} (Lowest DMC)",
|
199 |
'wweia_category': most_conservative_mapping['wweia_category'],
|
200 |
+
'foundation_category': most_conservative_mapping['foundation_category'],
|
201 |
'dry_matter_content': most_conservative_mapping['dry_matter_content'],
|
202 |
'water_content': most_conservative_mapping['water_content'],
|
203 |
'leakage': most_conservative_mapping['leakage']
|
|
|
283 |
|
284 |
mapping.update({
|
285 |
'wweia_category': dictionary_result['wweia_category'] if dictionary_result else None,
|
286 |
+
'foundation_category': dictionary_result['foundation_category'] if dictionary_result else None,
|
287 |
'water_content': dictionary_result['water_content'] if dictionary_result else None,
|
288 |
'dry_matter_content': dictionary_result['dry_matter_content'] if dictionary_result else None,
|
289 |
'leakage': dictionary_result['leakage'] if dictionary_result else None,
|
app.py
CHANGED
@@ -25,10 +25,10 @@ def process_input(input_text, csv_file):
|
|
25 |
|
26 |
|
27 |
print(f" - result -> {results}")
|
28 |
-
df = pd.DataFrame(results, columns=["input_word", "cleaned_word", 'matching_word', 'dictionary_word', '
|
29 |
'water_content', 'similarity_score', 'confidence_score', 'similar_words', 'is_food', 'food_nonfood_score'])
|
30 |
# Filter to only required columns
|
31 |
-
df_filtered = df[["input_word", "dictionary_word", "is_food", "
|
32 |
return df_filtered
|
33 |
|
34 |
# Gradio interface
|
|
|
25 |
|
26 |
|
27 |
print(f" - result -> {results}")
|
28 |
+
df = pd.DataFrame(results, columns=["input_word", "cleaned_word", 'matching_word', 'dictionary_word', 'foundation_category', 'wweia_category', 'dry_matter_content',
|
29 |
'water_content', 'similarity_score', 'confidence_score', 'similar_words', 'is_food', 'food_nonfood_score'])
|
30 |
# Filter to only required columns
|
31 |
+
df_filtered = df[["input_word", "dictionary_word", "is_food", "foundation_category", 'wweia_category', 'dry_matter_content', "water_content", "similarity_score", "food_nonfood_score"]]
|
32 |
return df_filtered
|
33 |
|
34 |
# Gradio interface
|
category_mapper.py
CHANGED
@@ -86,7 +86,7 @@ for row in tqdm(rows, desc="Processing"):
|
|
86 |
print()
|
87 |
fdc_id = row['fdc_id']
|
88 |
food_item = row['description']
|
89 |
-
category = row['
|
90 |
|
91 |
print(f"Processing '{food_item}'")
|
92 |
|
|
|
86 |
print()
|
87 |
fdc_id = row['fdc_id']
|
88 |
food_item = row['description']
|
89 |
+
category = row['foundation_category']
|
90 |
|
91 |
print(f"Processing '{food_item}'")
|
92 |
|
db/db_utils.py
CHANGED
@@ -44,7 +44,7 @@ def initialize_db(conn):
|
|
44 |
CREATE TABLE IF NOT EXISTS dictionary (
|
45 |
fdc_id INTEGER PRIMARY KEY,
|
46 |
description TEXT,
|
47 |
-
|
48 |
wweia_category TEXT,
|
49 |
water_content REAL,
|
50 |
dry_matter_content REAL,
|
@@ -63,7 +63,7 @@ def initialize_db(conn):
|
|
63 |
dictionary_word TEXT,
|
64 |
is_food BOOLEAN,
|
65 |
wweia_category TEXT,
|
66 |
-
|
67 |
dry_matter_content REAL,
|
68 |
leakage REAL,
|
69 |
weight REAL,
|
@@ -153,7 +153,7 @@ def store_mapping_to_db(cursor, conn, mapping):
|
|
153 |
def store_result_to_db(cursor, conn, run_key, result):
|
154 |
try:
|
155 |
cursor.execute('''
|
156 |
-
INSERT INTO results (run_key, run_row, date, input_word, dictionary_word, is_food,
|
157 |
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
158 |
''', (
|
159 |
run_key,
|
@@ -162,7 +162,7 @@ def store_result_to_db(cursor, conn, run_key, result):
|
|
162 |
result['input_word'],
|
163 |
result['dictionary_word'],
|
164 |
result['is_food'],
|
165 |
-
result['
|
166 |
result['wweia_category'],
|
167 |
result['dry_matter_content'],
|
168 |
result['leakage'],
|
|
|
44 |
CREATE TABLE IF NOT EXISTS dictionary (
|
45 |
fdc_id INTEGER PRIMARY KEY,
|
46 |
description TEXT,
|
47 |
+
foundation_category TEXT,
|
48 |
wweia_category TEXT,
|
49 |
water_content REAL,
|
50 |
dry_matter_content REAL,
|
|
|
63 |
dictionary_word TEXT,
|
64 |
is_food BOOLEAN,
|
65 |
wweia_category TEXT,
|
66 |
+
foundation_category TEXT,
|
67 |
dry_matter_content REAL,
|
68 |
leakage REAL,
|
69 |
weight REAL,
|
|
|
153 |
def store_result_to_db(cursor, conn, run_key, result):
|
154 |
try:
|
155 |
cursor.execute('''
|
156 |
+
INSERT INTO results (run_key, run_row, date, input_word, dictionary_word, is_food, foundation_category, wweia_category, dry_matter_content, leakage, weight, weight_metric_tonnes, donor, similarity_score, food_nonfood_score, distance, ef, mt_lb_mile, baseline_emissions, leakage_emissions, project_emissions, total_emissions_reduction)
|
157 |
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
158 |
''', (
|
159 |
run_key,
|
|
|
162 |
result['input_word'],
|
163 |
result['dictionary_word'],
|
164 |
result['is_food'],
|
165 |
+
result['foundation_category'],
|
166 |
result['wweia_category'],
|
167 |
result['dry_matter_content'],
|
168 |
result['leakage'],
|
mapping_template.py
CHANGED
@@ -9,7 +9,7 @@ def empty_template(input_word):
|
|
9 |
'food_nonfood_score': None,
|
10 |
'matching_word': None,
|
11 |
'dictionary_word': None,
|
12 |
-
'
|
13 |
'wweia_category': None,
|
14 |
'dry_matter_content': None,
|
15 |
'water_content': None,
|
|
|
9 |
'food_nonfood_score': None,
|
10 |
'matching_word': None,
|
11 |
'dictionary_word': None,
|
12 |
+
'foundation_category': None,
|
13 |
'wweia_category': None,
|
14 |
'dry_matter_content': None,
|
15 |
'water_content': None,
|