Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -402,7 +402,7 @@ def page1():
|
|
402 |
st.pyplot(fig)
|
403 |
|
404 |
# Explanation for the energy sustainability score calculation
|
405 |
-
|
406 |
|
407 |
The Energy Sustainability Score is calculated based on several factors related to sustainable energy practices in logistics operations. Here's how the score is composed:
|
408 |
|
@@ -455,7 +455,7 @@ def page1():
|
|
455 |
st.image("Eco-Novice.png", use_column_width=True)
|
456 |
Explanation = "You are at the early stages of implementing sustainable practices in your logistics operations. This is a great starting point, and there's much room for growth."
|
457 |
advice = "Begin by conducting a thorough energy audit to understand your current energy usage and identify areas for improvement. Focus on low-hanging fruits like switching to LED lighting, optimizing route planning to reduce fuel consumption, and training staff on energy conservation techniques. Consider simple measures like ensuring vehicles and equipment are well-maintained to improve fuel efficiency."
|
458 |
-
return f"**Sustainability Grade: {grade}** \n\n**Explanation:** \n{
|
459 |
|
460 |
|
461 |
def visualize_data(df):
|
@@ -482,6 +482,75 @@ def page1():
|
|
482 |
formatted_data[key] = format_answer(value)
|
483 |
return formatted_data
|
484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
def get_energy_report(all_answers, score):
|
486 |
"""Generates an Energy Sustainability report based on responses to a questionnaire."""
|
487 |
extracted_data = extract_data(all_answers)
|
@@ -586,7 +655,7 @@ def page1():
|
|
586 |
response = openai.ChatCompletion.create(
|
587 |
model="gpt-3.5-turbo",
|
588 |
messages=messages,
|
589 |
-
max_tokens=
|
590 |
temperature=0.3,
|
591 |
top_p=1.0,
|
592 |
frequency_penalty=0.5,
|
@@ -644,12 +713,13 @@ def page1():
|
|
644 |
|
645 |
st.subheader("Visualize Energy Scores")
|
646 |
score = calculate_energy_score(answers_df)
|
|
|
647 |
st.write(f"**Energy Sustainability Score:**")
|
648 |
st.markdown(f"**{score:.1f}%**")
|
649 |
# Call the function with the DataFrame
|
650 |
visualize_score_explanation(answers_df)
|
651 |
# Display the explanation in Streamlit
|
652 |
-
st.markdown(
|
653 |
|
654 |
st.subheader("Visualize Sustainability Grade")
|
655 |
# Call the function with the DataFrame
|
@@ -660,6 +730,13 @@ def page1():
|
|
660 |
strategy = get_energy_sustainability_advice(all_answers, company_data)
|
661 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
662 |
report = get_energy_report(all_answers, score)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
663 |
#st.subheader("Energy Sustainability Strategy")
|
664 |
st.subheader("Energy Sustainability Report")
|
665 |
st.write(report)
|
@@ -914,7 +991,7 @@ def page2():
|
|
914 |
# Convert answers to a DataFrame for analysis
|
915 |
answers_df = pd.DataFrame([all_answers])
|
916 |
|
917 |
-
st.write(all_answers)
|
918 |
|
919 |
# Display the collected answers
|
920 |
#st.write("Collected Answers:", answers_df)
|
@@ -1197,6 +1274,73 @@ def page2():
|
|
1197 |
return f"**Sustainability Grade: {grade}** \n\n**Explanation:** \n{Explanation} \n\n**Detailed Advice:** \n{advice}"
|
1198 |
|
1199 |
#st.markdown(evaluate_transport_sustainability_practice(score, answers_df), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1200 |
|
1201 |
def get_transport_sustainability_report(all_answers, score):
|
1202 |
"""Generates a Transport Sustainability report based on responses to a questionnaire."""
|
@@ -1319,7 +1463,7 @@ def page2():
|
|
1319 |
response = openai.ChatCompletion.create(
|
1320 |
model="gpt-3.5-turbo",
|
1321 |
messages=messages,
|
1322 |
-
max_tokens=
|
1323 |
temperature=0.3,
|
1324 |
top_p=1.0,
|
1325 |
frequency_penalty=0.5,
|
@@ -1408,7 +1552,14 @@ def page2():
|
|
1408 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
1409 |
report = get_transport_sustainability_report(all_answers, score)
|
1410 |
#st.subheader("Energy Sustainability Strategy")
|
1411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1412 |
st.write(report)
|
1413 |
st.download_button(
|
1414 |
label="Download Transport Sustainability Report",
|
@@ -1715,7 +1866,7 @@ def page3():
|
|
1715 |
|
1716 |
def Waste_Management_Practices(all_answers):
|
1717 |
# Visualize Count of 'Yes' and 'No' Responses
|
1718 |
-
st.
|
1719 |
st.write("**Yes/No Responses Overview:**")
|
1720 |
st.write("This chart shows the count of 'Yes' and 'No' responses to questions about waste management practices. A higher count of 'Yes' responses indicates proactive engagement in sustainable waste management.")
|
1721 |
|
@@ -1927,6 +2078,74 @@ def page3():
|
|
1927 |
|
1928 |
#st.markdown(evaluate_waste_sustainability_practice(score, answers_df), unsafe_allow_html=True)
|
1929 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1930 |
def evaluate_waste_sustainability_report(all_answers, score):
|
1931 |
"""Generates a Waste Sustainability report based on responses to a questionnaire."""
|
1932 |
extracted_data = extract_data(all_answers)
|
@@ -1991,7 +2210,7 @@ def page3():
|
|
1991 |
|
1992 |
try:
|
1993 |
response = openai.ChatCompletion.create(
|
1994 |
-
model="gpt-3.5-turbo",
|
1995 |
messages=[
|
1996 |
{"role": "system", "content": "Analyze the data and provide comprehensive insights and recommendations."},
|
1997 |
{"role": "user", "content": prompt}
|
@@ -2075,7 +2294,7 @@ def page3():
|
|
2075 |
additional_context = f"Provide a detailed waste sustainability strategy using context data from the above company info and in responses to the waste sustainability assessment."
|
2076 |
# Assuming you have an API call here to generate a response based on the prompt
|
2077 |
response = openai.ChatCompletion.create(
|
2078 |
-
model="gpt-3.5-turbo",
|
2079 |
messages=[
|
2080 |
{"role": "assistant", "content": "You are a waste sustainability strategy advisor."},
|
2081 |
{"role": "user", "content": prompt},
|
@@ -2102,7 +2321,7 @@ def page3():
|
|
2102 |
|
2103 |
# Query the OpenAI API for information on the certification process
|
2104 |
response = openai.ChatCompletion.create(
|
2105 |
-
model="gpt-3.5-turbo",
|
2106 |
messages=messages,
|
2107 |
max_tokens=2000,
|
2108 |
temperature=0.3,
|
@@ -2194,6 +2413,12 @@ def page3():
|
|
2194 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
2195 |
report = evaluate_waste_sustainability_report(all_answers, score)
|
2196 |
#st.subheader("Energy Sustainability Strategy")
|
|
|
|
|
|
|
|
|
|
|
|
|
2197 |
st.subheader("Waste Sustainability Report")
|
2198 |
st.write(report)
|
2199 |
st.download_button(
|
@@ -2327,12 +2552,20 @@ def page4():
|
|
2327 |
st.image("banner1.png", use_column_width=True)
|
2328 |
# Provide instructions for image upload
|
2329 |
|
|
|
2330 |
st.markdown("""
|
2331 |
-
**
|
2332 |
-
-
|
2333 |
-
- Use a plain background
|
2334 |
-
-
|
2335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2336 |
""")
|
2337 |
# Instructions and other static content can go here
|
2338 |
|
@@ -2346,6 +2579,10 @@ def page4():
|
|
2346 |
image = Image.open(uploaded_file)
|
2347 |
st.image(image, caption='Uploaded Trash Image', use_column_width=True)
|
2348 |
|
|
|
|
|
|
|
|
|
2349 |
# Encode the image for GPT-4 Vision API
|
2350 |
encoded_image = encode_image(image)
|
2351 |
|
@@ -2881,6 +3118,74 @@ def page5():
|
|
2881 |
|
2882 |
return f"**Sustainability Grade: {grade}** \n\n**Explanation:** \n{explanation} \n\n**Detailed Advice:** \n{advice}"
|
2883 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2884 |
def evaluate_emission_sustainability_report(all_answers, score):
|
2885 |
"""Generates an Emission Sustainability report based on responses to a questionnaire."""
|
2886 |
extracted_data = extract_data(all_answers)
|
@@ -2923,7 +3228,7 @@ def page5():
|
|
2923 |
|
2924 |
try:
|
2925 |
response = openai.ChatCompletion.create(
|
2926 |
-
model="gpt-3.5-turbo",
|
2927 |
messages=[
|
2928 |
{"role": "system", "content": "Analyze the data and provide comprehensive insights and recommendations."},
|
2929 |
{"role": "user", "content": prompt}
|
@@ -3001,7 +3306,7 @@ def page5():
|
|
3001 |
additional_context = f"Provide a detailed emission sustainability strategy using context data from the above company info and in responses to the emission sustainability assessment."
|
3002 |
# Assuming you have an API call here to generate a response based on the prompt
|
3003 |
response = openai.ChatCompletion.create(
|
3004 |
-
model="gpt-3.5-turbo",
|
3005 |
messages=[
|
3006 |
{"role": "assistant", "content": "You are an emission sustainability strategy advisor."},
|
3007 |
{"role": "user", "content": prompt},
|
@@ -3118,6 +3423,11 @@ def page5():
|
|
3118 |
|
3119 |
st.markdown(evaluate_emission_sustainability_practice(score, answers_df), unsafe_allow_html=True)
|
3120 |
|
|
|
|
|
|
|
|
|
|
|
3121 |
strategy = get_emission_sustainability_strategy(all_answers, company_data)
|
3122 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
3123 |
report = evaluate_emission_sustainability_report(all_answers, score)
|
@@ -3182,8 +3492,8 @@ def page6():
|
|
3182 |
API_KEY = "XXtYmhThBssK41ufq2JJOA"
|
3183 |
# Define headers for the API call
|
3184 |
headers = {
|
3185 |
-
|
3186 |
-
|
3187 |
}
|
3188 |
|
3189 |
# Streamlit UI
|
@@ -3247,290 +3557,492 @@ def page6():
|
|
3247 |
|
3248 |
# List of sample IATA Codes
|
3249 |
iata_samples = [
|
3250 |
-
|
3251 |
-
|
3252 |
-
|
3253 |
-
|
3254 |
-
|
3255 |
-
|
3256 |
-
|
3257 |
-
|
3258 |
]
|
3259 |
|
3260 |
|
3261 |
|
3262 |
# Dropdown for Departure Airport
|
3263 |
-
|
3264 |
-
departure_airport = st.selectbox("Departure Airport (IATA Code)", departure_airport_options, key='departure_airport')
|
3265 |
-
|
|
|
3266 |
# Dropdown for Destination Airport
|
3267 |
# Filter destinations based on selected departure airport
|
3268 |
-
|
3269 |
-
destination_airport = st.selectbox("Destination Airport (IATA Code)", destination_airport_options, key='destination_airport')
|
3270 |
|
3271 |
-
|
3272 |
COEFFICIENTS = {
|
3273 |
-
|
3274 |
-
|
3275 |
-
|
3276 |
-
|
3277 |
}
|
3278 |
|
3279 |
fuel_source_units = {
|
3280 |
-
|
3281 |
-
|
3282 |
-
|
3283 |
-
|
3284 |
}
|
3285 |
|
3286 |
def calculate_emissions(fuel_type, fuel_unit, fuel_value):
|
3287 |
-
|
3288 |
-
|
3289 |
-
|
3290 |
-
|
3291 |
-
|
3292 |
-
|
3293 |
-
|
3294 |
|
3295 |
-
|
3296 |
-
|
3297 |
-
|
3298 |
-
|
3299 |
-
|
3300 |
-
|
3301 |
|
3302 |
-
|
3303 |
-
|
3304 |
-
|
3305 |
|
3306 |
-
|
3307 |
|
3308 |
-
|
3309 |
|
3310 |
# User Interface Simplification
|
3311 |
#st.write("**Fuel Combustion CO2 Emissions Calculator**")
|
3312 |
st.subheader("8. Fuel Combustion Emissions")
|
3313 |
# Reduced list of selectable fuel sources
|
3314 |
-
selected_fuel_sources = st.multiselect("Choose Fuel Source", ["diesel", "gasoline", "natural_gas"
|
|
|
|
|
|
|
3315 |
|
3316 |
total_emissions = 0
|
3317 |
|
3318 |
for fuel_source in selected_fuel_sources:
|
3319 |
-
|
|
|
|
|
|
|
3320 |
|
3321 |
-
|
3322 |
-
|
3323 |
|
3324 |
-
|
3325 |
-
|
|
|
3326 |
|
3327 |
-
|
3328 |
-
emission = calculate_emissions(fuel_source, fuel_source_unit, fuel_source_value)
|
3329 |
-
st.write(f"CO2 emissions for {fuel_source}: {emission:.2f} grams")
|
3330 |
|
3331 |
-
total_emissions += emission
|
3332 |
|
3333 |
# Button to trigger the calculations
|
3334 |
if st.button("Calculate Carbon Emission"):
|
3335 |
-
st.spinner("Calculating...")
|
3336 |
|
3337 |
-
|
3338 |
|
3339 |
-
|
3340 |
-
|
3341 |
-
|
3342 |
-
|
3343 |
-
|
3344 |
-
|
3345 |
-
|
3346 |
-
|
3347 |
-
|
3348 |
-
|
3349 |
-
else:
|
3350 |
-
results["Electricity Error"] = f"Error: {response_electricity.status_code} - {response_electricity.text}"
|
3351 |
-
|
3352 |
-
# Vehicle API Call
|
3353 |
-
if vehicle_model_id: # Only make the API call if a vehicle_model_id is provided
|
3354 |
-
payload_vehicle = {
|
3355 |
-
"type": "vehicle",
|
3356 |
-
"distance_unit": distance_unit_vehicle,
|
3357 |
-
"distance_value": distance_value_vehicle,
|
3358 |
-
"vehicle_model_id": vehicle_model_id
|
3359 |
-
}
|
3360 |
-
response_vehicle = requests.post(API_URL, json=payload_vehicle, headers=headers)
|
3361 |
-
if response_vehicle.status_code == 201:
|
3362 |
-
results["Vehicle"] = response_vehicle.json().get("data", {}).get("attributes", {})
|
3363 |
else:
|
3364 |
-
|
3365 |
-
|
3366 |
-
#
|
3367 |
-
|
3368 |
-
|
3369 |
-
|
3370 |
-
|
3371 |
-
|
3372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3373 |
}
|
3374 |
-
response_flight = requests.post(API_URL, json=payload_flight, headers=headers)
|
3375 |
-
if response_flight.status_code == 201:
|
3376 |
-
results["Flight"] = response_flight.json().get("data", {}).get("attributes", {})
|
3377 |
-
else:
|
3378 |
-
results["Flight Error"] = f"Error: {response_flight.status_code} - {response_flight.text}"
|
3379 |
|
3380 |
-
|
3381 |
-
|
3382 |
-
|
3383 |
-
|
3384 |
-
|
3385 |
-
|
3386 |
-
|
3387 |
-
|
3388 |
-
|
3389 |
-
|
3390 |
-
|
3391 |
-
|
3392 |
-
|
3393 |
-
|
3394 |
-
|
3395 |
-
|
3396 |
-
|
3397 |
-
|
3398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3399 |
|
3400 |
-
|
3401 |
-
|
|
|
|
|
3402 |
|
3403 |
-
|
3404 |
-
st.pyplot(fig)
|
3405 |
|
3406 |
-
|
3407 |
-
|
|
|
|
|
3408 |
|
3409 |
-
|
|
|
|
|
|
|
|
|
|
|
3410 |
|
3411 |
-
|
3412 |
-
|
3413 |
|
3414 |
-
|
3415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3416 |
|
3417 |
-
# Calculate the emissions after the desired reduction target is applied
|
3418 |
-
emissions_after_reduction = total_emissions * (1 - (reduction_target / 100))
|
3419 |
|
3420 |
-
|
3421 |
-
|
3422 |
-
|
3423 |
-
|
3424 |
-
|
3425 |
-
|
3426 |
-
|
3427 |
-
|
3428 |
-
|
3429 |
-
|
3430 |
-
|
3431 |
-
|
3432 |
-
|
3433 |
-
|
3434 |
-
|
3435 |
-
|
3436 |
-
|
3437 |
-
|
3438 |
-
|
3439 |
-
|
3440 |
-
|
3441 |
-
|
3442 |
-
|
3443 |
-
|
3444 |
-
|
3445 |
-
|
3446 |
-
|
3447 |
-
|
3448 |
-
|
3449 |
-
|
3450 |
-
|
3451 |
-
|
3452 |
-
},
|
3453 |
-
"packaging": {
|
3454 |
-
"material": "packaging_material",
|
3455 |
-
},
|
3456 |
-
"fleet_management": {
|
3457 |
-
"percentage_electric": "percentage_electric_vehicles",
|
3458 |
-
"average_age": "average_age_of_ships",
|
3459 |
-
},
|
3460 |
-
"vehicular_emissions": {
|
3461 |
-
"distance_unit": "distance_unit_vehicle",
|
3462 |
-
"distance_value": "distance_value_vehicle",
|
3463 |
-
"model_id": "vehicle_model_id",
|
3464 |
-
},
|
3465 |
-
"fuel_combustion_emissions": {
|
3466 |
-
"selected_fuel_sources": "selected_fuel_sources",
|
3467 |
-
"total_emissions": "total_emissions",
|
3468 |
-
},
|
3469 |
-
"emission_reduction_goals": {
|
3470 |
-
# Initialize with empty strings or appropriate placeholders
|
3471 |
-
"current_emissions": "",
|
3472 |
-
"emissions_after_target": "",
|
3473 |
-
"reduction_target": "",
|
3474 |
-
},
|
3475 |
-
}
|
3476 |
|
3477 |
-
|
3478 |
-
|
3479 |
-
|
3480 |
-
|
3481 |
-
|
3482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3483 |
|
3484 |
-
# Update the responses dictionary with the new data
|
3485 |
-
# Now when you try to update the 'emission_reduction_goals' it should work without errors
|
3486 |
-
responses["emission_reduction_goals"]["current_emissions"] = total_emissions
|
3487 |
-
responses["emission_reduction_goals"]["emissions_after_target"] = emissions_after_reduction
|
3488 |
-
responses["emission_reduction_goals"]["reduction_target"] = reduction_target
|
3489 |
|
3490 |
-
# Formulate the prompt for GPT
|
3491 |
-
prompt = f"""
|
3492 |
-
Detailed carbon emission results and targets:
|
3493 |
|
3494 |
-
{responses}
|
3495 |
|
3496 |
-
|
3497 |
-
|
3498 |
-
|
3499 |
-
- Fuel combustion emissions
|
3500 |
-
- Electricity use in port operations
|
3501 |
-
- Fleet management practices
|
3502 |
-
- Shipping route efficiency
|
3503 |
|
3504 |
-
|
3505 |
-
"""
|
3506 |
|
3507 |
-
|
3508 |
-
|
3509 |
-
|
3510 |
-
|
3511 |
-
|
3512 |
-
|
3513 |
-
|
3514 |
-
|
3515 |
-
|
3516 |
-
|
3517 |
-
|
3518 |
-
|
3519 |
-
|
3520 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3521 |
|
3522 |
-
# Extracting the advice content from the response
|
3523 |
-
advice_content = response.choices[0].message['content']
|
3524 |
-
# Display the advice to the user
|
3525 |
-
st.subheader("Sustainability Advice")
|
3526 |
-
st.write(advice_content)
|
3527 |
-
st.download_button(
|
3528 |
-
label="Download Sustainability advice",
|
3529 |
-
data=advice_content,
|
3530 |
-
file_name='sustainability_advice.txt',
|
3531 |
-
mime='text/txt',
|
3532 |
-
key="download_advice_button", # Unique key for this button
|
3533 |
-
)
|
3534 |
|
3535 |
# Display a disclaimer message
|
3536 |
st.warning("Disclaimer: The carbon emission calculations provided here are based on certain assumptions and data sources. While we strive to provide accurate estimates, please be aware that the results should be considered as approximate. For the most accurate carbon emissions assessment, we recommend testing with globally accepted values and results.")
|
@@ -3540,6 +4052,7 @@ def page6():
|
|
3540 |
*Powered by Streamlit, CarbonInterface API, and OpenAI.*
|
3541 |
""")
|
3542 |
|
|
|
3543 |
def page7():
|
3544 |
# Load and set OpenAI API key from file
|
3545 |
os.environ["OPENAI_API_KEY"] = open("key.txt", "r").read().strip("\n")
|
|
|
402 |
st.pyplot(fig)
|
403 |
|
404 |
# Explanation for the energy sustainability score calculation
|
405 |
+
explanation_E_eval = """
|
406 |
|
407 |
The Energy Sustainability Score is calculated based on several factors related to sustainable energy practices in logistics operations. Here's how the score is composed:
|
408 |
|
|
|
455 |
st.image("Eco-Novice.png", use_column_width=True)
|
456 |
Explanation = "You are at the early stages of implementing sustainable practices in your logistics operations. This is a great starting point, and there's much room for growth."
|
457 |
advice = "Begin by conducting a thorough energy audit to understand your current energy usage and identify areas for improvement. Focus on low-hanging fruits like switching to LED lighting, optimizing route planning to reduce fuel consumption, and training staff on energy conservation techniques. Consider simple measures like ensuring vehicles and equipment are well-maintained to improve fuel efficiency."
|
458 |
+
return f"**Sustainability Grade: {grade}** \n\n**Explanation:** \n{Explanation} \n\n**Basic Advice:** \n{advice}"
|
459 |
|
460 |
|
461 |
def visualize_data(df):
|
|
|
482 |
formatted_data[key] = format_answer(value)
|
483 |
return formatted_data
|
484 |
|
485 |
+
def generate_swot_analysis(company_data):
|
486 |
+
# Extracting relevant data from company_data
|
487 |
+
logistics_sustainability_level = company_data.get("Logistics Sustainability Level", "None")
|
488 |
+
annual_carbon_emissions = company_data.get("Annual Carbon Emissions (in metric tons)", 0)
|
489 |
+
utilize_renewable_energy = company_data.get("Utilize Renewable Energy Sources", False)
|
490 |
+
selected_certifications = company_data.get("Selected Logistics Certifications and Initiatives", [])
|
491 |
+
company_summary = company_data.get("Company Summary", "No specific information provided.")
|
492 |
+
|
493 |
+
# Constructing a dynamic SWOT analysis based on extracted data
|
494 |
+
strengths = [
|
495 |
+
"Utilization of Renewable Energy Sources" if utilize_renewable_energy else "None"
|
496 |
+
]
|
497 |
+
|
498 |
+
weaknesses = [
|
499 |
+
"Lack of Logistics Sustainability Level: " + logistics_sustainability_level,
|
500 |
+
"Zero Annual Carbon Emissions" if annual_carbon_emissions == 0 else "Annual Carbon Emissions Present",
|
501 |
+
"Company Summary: " + company_summary
|
502 |
+
]
|
503 |
+
|
504 |
+
opportunities = [
|
505 |
+
"Exploration of Logistics Certifications" if not selected_certifications else "None"
|
506 |
+
]
|
507 |
+
|
508 |
+
threats = [
|
509 |
+
"Competitive Disadvantage Due to Lack of Certifications" if not selected_certifications else "None"
|
510 |
+
]
|
511 |
+
|
512 |
+
# Constructing a SWOT analysis prompt dynamically
|
513 |
+
swot_analysis_prompt = f"""
|
514 |
+
Strengths, Weaknesses, Opportunities, Threats (SWOT) Analysis:
|
515 |
+
|
516 |
+
Strengths:
|
517 |
+
Strengths Analysis:
|
518 |
+
{", ".join(strengths)}
|
519 |
+
|
520 |
+
Weaknesses:
|
521 |
+
Weaknesses Analysis:
|
522 |
+
{", ".join(weaknesses)}
|
523 |
+
|
524 |
+
Opportunities:
|
525 |
+
Opportunities Analysis:
|
526 |
+
{", ".join(opportunities)}
|
527 |
+
|
528 |
+
Threats:
|
529 |
+
Threats Analysis:
|
530 |
+
{", ".join(threats)}
|
531 |
+
"""
|
532 |
+
|
533 |
+
# OpenAI API call for SWOT analysis
|
534 |
+
response_swot = openai.ChatCompletion.create(
|
535 |
+
model="gpt-3.5-turbo",
|
536 |
+
messages=[
|
537 |
+
{"role": "assistant", "content": "You are analyzing the company's sustainability practices."},
|
538 |
+
{"role": "system", "content": "Conduct a SWOT analysis based on the provided company data."},
|
539 |
+
{"role": "user", "content": swot_analysis_prompt}
|
540 |
+
],
|
541 |
+
max_tokens=1000,
|
542 |
+
temperature=0.5,
|
543 |
+
top_p=1.0,
|
544 |
+
frequency_penalty=0.5,
|
545 |
+
presence_penalty=0.0
|
546 |
+
)
|
547 |
+
|
548 |
+
# Extracting the SWOT analysis content from the response
|
549 |
+
swot_analysis_content = response_swot.choices[0].message['content']
|
550 |
+
|
551 |
+
return swot_analysis_content
|
552 |
+
|
553 |
+
|
554 |
def get_energy_report(all_answers, score):
|
555 |
"""Generates an Energy Sustainability report based on responses to a questionnaire."""
|
556 |
extracted_data = extract_data(all_answers)
|
|
|
655 |
response = openai.ChatCompletion.create(
|
656 |
model="gpt-3.5-turbo",
|
657 |
messages=messages,
|
658 |
+
max_tokens=1500,
|
659 |
temperature=0.3,
|
660 |
top_p=1.0,
|
661 |
frequency_penalty=0.5,
|
|
|
713 |
|
714 |
st.subheader("Visualize Energy Scores")
|
715 |
score = calculate_energy_score(answers_df)
|
716 |
+
|
717 |
st.write(f"**Energy Sustainability Score:**")
|
718 |
st.markdown(f"**{score:.1f}%**")
|
719 |
# Call the function with the DataFrame
|
720 |
visualize_score_explanation(answers_df)
|
721 |
# Display the explanation in Streamlit
|
722 |
+
st.markdown(explanation_E_eval)
|
723 |
|
724 |
st.subheader("Visualize Sustainability Grade")
|
725 |
# Call the function with the DataFrame
|
|
|
730 |
strategy = get_energy_sustainability_advice(all_answers, company_data)
|
731 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
732 |
report = get_energy_report(all_answers, score)
|
733 |
+
|
734 |
+
# Extracting the SWOT analysis content from the response
|
735 |
+
swot_analysis_content = generate_swot_analysis(company_data)
|
736 |
+
#st.subheader("Energy Sustainability Strategy")
|
737 |
+
st.subheader("Company SWOT Report")
|
738 |
+
st.write(swot_analysis_content)
|
739 |
+
|
740 |
#st.subheader("Energy Sustainability Strategy")
|
741 |
st.subheader("Energy Sustainability Report")
|
742 |
st.write(report)
|
|
|
991 |
# Convert answers to a DataFrame for analysis
|
992 |
answers_df = pd.DataFrame([all_answers])
|
993 |
|
994 |
+
#st.write(all_answers)
|
995 |
|
996 |
# Display the collected answers
|
997 |
#st.write("Collected Answers:", answers_df)
|
|
|
1274 |
return f"**Sustainability Grade: {grade}** \n\n**Explanation:** \n{Explanation} \n\n**Detailed Advice:** \n{advice}"
|
1275 |
|
1276 |
#st.markdown(evaluate_transport_sustainability_practice(score, answers_df), unsafe_allow_html=True)
|
1277 |
+
def generate_swot_analysis(company_data):
|
1278 |
+
# Extracting relevant data from company_data
|
1279 |
+
logistics_sustainability_level = company_data.get("Logistics Sustainability Level", "None")
|
1280 |
+
annual_carbon_emissions = company_data.get("Annual Carbon Emissions (in metric tons)", 0)
|
1281 |
+
utilize_renewable_energy = company_data.get("Utilize Renewable Energy Sources", False)
|
1282 |
+
selected_certifications = company_data.get("Selected Logistics Certifications and Initiatives", [])
|
1283 |
+
company_summary = company_data.get("Company Summary", "No specific information provided.")
|
1284 |
+
|
1285 |
+
# Constructing a dynamic SWOT analysis based on extracted data
|
1286 |
+
strengths = [
|
1287 |
+
"Utilization of Renewable Energy Sources" if utilize_renewable_energy else "None"
|
1288 |
+
]
|
1289 |
+
|
1290 |
+
weaknesses = [
|
1291 |
+
"Lack of Logistics Sustainability Level: " + logistics_sustainability_level,
|
1292 |
+
"Zero Annual Carbon Emissions" if annual_carbon_emissions == 0 else "Annual Carbon Emissions Present",
|
1293 |
+
"Company Summary: " + company_summary
|
1294 |
+
]
|
1295 |
+
|
1296 |
+
opportunities = [
|
1297 |
+
"Exploration of Logistics Certifications" if not selected_certifications else "None"
|
1298 |
+
]
|
1299 |
+
|
1300 |
+
threats = [
|
1301 |
+
"Competitive Disadvantage Due to Lack of Certifications" if not selected_certifications else "None"
|
1302 |
+
]
|
1303 |
+
|
1304 |
+
# Constructing a SWOT analysis prompt dynamically
|
1305 |
+
swot_analysis_prompt = f"""
|
1306 |
+
Strengths, Weaknesses, Opportunities, Threats (SWOT) Analysis:
|
1307 |
+
|
1308 |
+
Strengths:
|
1309 |
+
Strengths Analysis:
|
1310 |
+
{", ".join(strengths)}
|
1311 |
+
|
1312 |
+
Weaknesses:
|
1313 |
+
Weaknesses Analysis:
|
1314 |
+
{", ".join(weaknesses)}
|
1315 |
+
|
1316 |
+
Opportunities:
|
1317 |
+
Opportunities Analysis:
|
1318 |
+
{", ".join(opportunities)}
|
1319 |
+
|
1320 |
+
Threats:
|
1321 |
+
Threats Analysis:
|
1322 |
+
{", ".join(threats)}
|
1323 |
+
"""
|
1324 |
+
|
1325 |
+
# OpenAI API call for SWOT analysis
|
1326 |
+
response_swot = openai.ChatCompletion.create(
|
1327 |
+
model="gpt-3.5-turbo",
|
1328 |
+
messages=[
|
1329 |
+
{"role": "assistant", "content": "You are analyzing the company's sustainability practices."},
|
1330 |
+
{"role": "system", "content": "Conduct a SWOT analysis based on the provided company data."},
|
1331 |
+
{"role": "user", "content": swot_analysis_prompt}
|
1332 |
+
],
|
1333 |
+
max_tokens=1000,
|
1334 |
+
temperature=0.5,
|
1335 |
+
top_p=1.0,
|
1336 |
+
frequency_penalty=0.5,
|
1337 |
+
presence_penalty=0.0
|
1338 |
+
)
|
1339 |
+
|
1340 |
+
# Extracting the SWOT analysis content from the response
|
1341 |
+
swot_analysis_content = response_swot.choices[0].message['content']
|
1342 |
+
|
1343 |
+
return swot_analysis_content
|
1344 |
|
1345 |
def get_transport_sustainability_report(all_answers, score):
|
1346 |
"""Generates a Transport Sustainability report based on responses to a questionnaire."""
|
|
|
1463 |
response = openai.ChatCompletion.create(
|
1464 |
model="gpt-3.5-turbo",
|
1465 |
messages=messages,
|
1466 |
+
max_tokens=1500,
|
1467 |
temperature=0.3,
|
1468 |
top_p=1.0,
|
1469 |
frequency_penalty=0.5,
|
|
|
1552 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
1553 |
report = get_transport_sustainability_report(all_answers, score)
|
1554 |
#st.subheader("Energy Sustainability Strategy")
|
1555 |
+
|
1556 |
+
# Extracting the SWOT analysis content from the response
|
1557 |
+
swot_analysis_content = generate_swot_analysis(company_data)
|
1558 |
+
#st.subheader("Energy Sustainability Strategy")
|
1559 |
+
st.subheader("Company SWOT Report")
|
1560 |
+
st.write(swot_analysis_content)
|
1561 |
+
|
1562 |
+
st.subheader("Transport Sustainability Report")
|
1563 |
st.write(report)
|
1564 |
st.download_button(
|
1565 |
label="Download Transport Sustainability Report",
|
|
|
1866 |
|
1867 |
def Waste_Management_Practices(all_answers):
|
1868 |
# Visualize Count of 'Yes' and 'No' Responses
|
1869 |
+
st.subheader("Waste Management Practices")
|
1870 |
st.write("**Yes/No Responses Overview:**")
|
1871 |
st.write("This chart shows the count of 'Yes' and 'No' responses to questions about waste management practices. A higher count of 'Yes' responses indicates proactive engagement in sustainable waste management.")
|
1872 |
|
|
|
2078 |
|
2079 |
#st.markdown(evaluate_waste_sustainability_practice(score, answers_df), unsafe_allow_html=True)
|
2080 |
|
2081 |
+
def generate_swot_analysis(company_data):
|
2082 |
+
# Extracting relevant data from company_data
|
2083 |
+
logistics_sustainability_level = company_data.get("Logistics Sustainability Level", "None")
|
2084 |
+
annual_carbon_emissions = company_data.get("Annual Carbon Emissions (in metric tons)", 0)
|
2085 |
+
utilize_renewable_energy = company_data.get("Utilize Renewable Energy Sources", False)
|
2086 |
+
selected_certifications = company_data.get("Selected Logistics Certifications and Initiatives", [])
|
2087 |
+
company_summary = company_data.get("Company Summary", "No specific information provided.")
|
2088 |
+
|
2089 |
+
# Constructing a dynamic SWOT analysis based on extracted data
|
2090 |
+
strengths = [
|
2091 |
+
"Utilization of Renewable Energy Sources" if utilize_renewable_energy else "None"
|
2092 |
+
]
|
2093 |
+
|
2094 |
+
weaknesses = [
|
2095 |
+
"Lack of Logistics Sustainability Level: " + logistics_sustainability_level,
|
2096 |
+
"Zero Annual Carbon Emissions" if annual_carbon_emissions == 0 else "Annual Carbon Emissions Present",
|
2097 |
+
"Company Summary: " + company_summary
|
2098 |
+
]
|
2099 |
+
|
2100 |
+
opportunities = [
|
2101 |
+
"Exploration of Logistics Certifications" if not selected_certifications else "None"
|
2102 |
+
]
|
2103 |
+
|
2104 |
+
threats = [
|
2105 |
+
"Competitive Disadvantage Due to Lack of Certifications" if not selected_certifications else "None"
|
2106 |
+
]
|
2107 |
+
|
2108 |
+
# Constructing a SWOT analysis prompt dynamically
|
2109 |
+
swot_analysis_prompt = f"""
|
2110 |
+
Strengths, Weaknesses, Opportunities, Threats (SWOT) Analysis:
|
2111 |
+
|
2112 |
+
Strengths:
|
2113 |
+
Strengths Analysis:
|
2114 |
+
{", ".join(strengths)}
|
2115 |
+
|
2116 |
+
Weaknesses:
|
2117 |
+
Weaknesses Analysis:
|
2118 |
+
{", ".join(weaknesses)}
|
2119 |
+
|
2120 |
+
Opportunities:
|
2121 |
+
Opportunities Analysis:
|
2122 |
+
{", ".join(opportunities)}
|
2123 |
+
|
2124 |
+
Threats:
|
2125 |
+
Threats Analysis:
|
2126 |
+
{", ".join(threats)}
|
2127 |
+
"""
|
2128 |
+
|
2129 |
+
# OpenAI API call for SWOT analysis
|
2130 |
+
response_swot = openai.ChatCompletion.create(
|
2131 |
+
model="gpt-3.5-turbo-16k",
|
2132 |
+
messages=[
|
2133 |
+
{"role": "assistant", "content": "You are analyzing the company's sustainability practices."},
|
2134 |
+
{"role": "system", "content": "Conduct a SWOT analysis based on the provided company data."},
|
2135 |
+
{"role": "user", "content": swot_analysis_prompt}
|
2136 |
+
],
|
2137 |
+
max_tokens=1000,
|
2138 |
+
temperature=0.5,
|
2139 |
+
top_p=1.0,
|
2140 |
+
frequency_penalty=0.5,
|
2141 |
+
presence_penalty=0.0
|
2142 |
+
)
|
2143 |
+
|
2144 |
+
# Extracting the SWOT analysis content from the response
|
2145 |
+
swot_analysis_content = response_swot.choices[0].message['content']
|
2146 |
+
|
2147 |
+
return swot_analysis_content
|
2148 |
+
|
2149 |
def evaluate_waste_sustainability_report(all_answers, score):
|
2150 |
"""Generates a Waste Sustainability report based on responses to a questionnaire."""
|
2151 |
extracted_data = extract_data(all_answers)
|
|
|
2210 |
|
2211 |
try:
|
2212 |
response = openai.ChatCompletion.create(
|
2213 |
+
model="gpt-3.5-turbo-16k",
|
2214 |
messages=[
|
2215 |
{"role": "system", "content": "Analyze the data and provide comprehensive insights and recommendations."},
|
2216 |
{"role": "user", "content": prompt}
|
|
|
2294 |
additional_context = f"Provide a detailed waste sustainability strategy using context data from the above company info and in responses to the waste sustainability assessment."
|
2295 |
# Assuming you have an API call here to generate a response based on the prompt
|
2296 |
response = openai.ChatCompletion.create(
|
2297 |
+
model="gpt-3.5-turbo-16k",
|
2298 |
messages=[
|
2299 |
{"role": "assistant", "content": "You are a waste sustainability strategy advisor."},
|
2300 |
{"role": "user", "content": prompt},
|
|
|
2321 |
|
2322 |
# Query the OpenAI API for information on the certification process
|
2323 |
response = openai.ChatCompletion.create(
|
2324 |
+
model="gpt-3.5-turbo-16k",
|
2325 |
messages=messages,
|
2326 |
max_tokens=2000,
|
2327 |
temperature=0.3,
|
|
|
2413 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
2414 |
report = evaluate_waste_sustainability_report(all_answers, score)
|
2415 |
#st.subheader("Energy Sustainability Strategy")
|
2416 |
+
# Extracting the SWOT analysis content from the response
|
2417 |
+
swot_analysis_content = generate_swot_analysis(company_data)
|
2418 |
+
#st.subheader("Energy Sustainability Strategy")
|
2419 |
+
st.subheader("Company SWOT Report")
|
2420 |
+
st.write(swot_analysis_content)
|
2421 |
+
|
2422 |
st.subheader("Waste Sustainability Report")
|
2423 |
st.write(report)
|
2424 |
st.download_button(
|
|
|
2552 |
st.image("banner1.png", use_column_width=True)
|
2553 |
# Provide instructions for image upload
|
2554 |
|
2555 |
+
# Providing instructions for image upload
|
2556 |
st.markdown("""
|
2557 |
+
**Step 1: Capture a Clear Image**
|
2558 |
+
- Center the trash item in your photo.
|
2559 |
+
- Use a plain, contrasting background.
|
2560 |
+
- Ensure good lighting to make the item clearly visible.
|
2561 |
+
|
2562 |
+
**Step 2: Upload Your Image**
|
2563 |
+
- Click 'Browse' to select your image file (JPG, JPEG, or PNG format).
|
2564 |
+
|
2565 |
+
**Step 3: Analyze and Get Insights**
|
2566 |
+
- Once the image is uploaded, click 'Analyze Image' to receive your classification and sustainable disposal advice.
|
2567 |
+
|
2568 |
+
**Note:** For best results, avoid including multiple items or excessive background clutter in your image.
|
2569 |
""")
|
2570 |
# Instructions and other static content can go here
|
2571 |
|
|
|
2579 |
image = Image.open(uploaded_file)
|
2580 |
st.image(image, caption='Uploaded Trash Image', use_column_width=True)
|
2581 |
|
2582 |
+
# Placeholder for analysis function call
|
2583 |
+
st.success("Image analysis successful! (Placeholder for actual analysis results)")
|
2584 |
+
|
2585 |
+
|
2586 |
# Encode the image for GPT-4 Vision API
|
2587 |
encoded_image = encode_image(image)
|
2588 |
|
|
|
3118 |
|
3119 |
return f"**Sustainability Grade: {grade}** \n\n**Explanation:** \n{explanation} \n\n**Detailed Advice:** \n{advice}"
|
3120 |
|
3121 |
+
def generate_swot_analysis(company_data):
|
3122 |
+
# Extracting relevant data from company_data
|
3123 |
+
logistics_sustainability_level = company_data.get("Logistics Sustainability Level", "None")
|
3124 |
+
annual_carbon_emissions = company_data.get("Annual Carbon Emissions (in metric tons)", 0)
|
3125 |
+
utilize_renewable_energy = company_data.get("Utilize Renewable Energy Sources", False)
|
3126 |
+
selected_certifications = company_data.get("Selected Logistics Certifications and Initiatives", [])
|
3127 |
+
company_summary = company_data.get("Company Summary", "No specific information provided.")
|
3128 |
+
|
3129 |
+
# Constructing a dynamic SWOT analysis based on extracted data
|
3130 |
+
strengths = [
|
3131 |
+
"Utilization of Renewable Energy Sources" if utilize_renewable_energy else "None"
|
3132 |
+
]
|
3133 |
+
|
3134 |
+
weaknesses = [
|
3135 |
+
"Lack of Logistics Sustainability Level: " + logistics_sustainability_level,
|
3136 |
+
"Zero Annual Carbon Emissions" if annual_carbon_emissions == 0 else "Annual Carbon Emissions Present",
|
3137 |
+
"Company Summary: " + company_summary
|
3138 |
+
]
|
3139 |
+
|
3140 |
+
opportunities = [
|
3141 |
+
"Exploration of Logistics Certifications" if not selected_certifications else "None"
|
3142 |
+
]
|
3143 |
+
|
3144 |
+
threats = [
|
3145 |
+
"Competitive Disadvantage Due to Lack of Certifications" if not selected_certifications else "None"
|
3146 |
+
]
|
3147 |
+
|
3148 |
+
# Constructing a SWOT analysis prompt dynamically
|
3149 |
+
swot_analysis_prompt = f"""
|
3150 |
+
Strengths, Weaknesses, Opportunities, Threats (SWOT) Analysis:
|
3151 |
+
|
3152 |
+
Strengths:
|
3153 |
+
Strengths Analysis:
|
3154 |
+
{", ".join(strengths)}
|
3155 |
+
|
3156 |
+
Weaknesses:
|
3157 |
+
Weaknesses Analysis:
|
3158 |
+
{", ".join(weaknesses)}
|
3159 |
+
|
3160 |
+
Opportunities:
|
3161 |
+
Opportunities Analysis:
|
3162 |
+
{", ".join(opportunities)}
|
3163 |
+
|
3164 |
+
Threats:
|
3165 |
+
Threats Analysis:
|
3166 |
+
{", ".join(threats)}
|
3167 |
+
"""
|
3168 |
+
|
3169 |
+
# OpenAI API call for SWOT analysis
|
3170 |
+
response_swot = openai.ChatCompletion.create(
|
3171 |
+
model="gpt-3.5-turbo",
|
3172 |
+
messages=[
|
3173 |
+
{"role": "assistant", "content": "You are analyzing the company's sustainability practices."},
|
3174 |
+
{"role": "system", "content": "Conduct a SWOT analysis based on the provided company data."},
|
3175 |
+
{"role": "user", "content": swot_analysis_prompt}
|
3176 |
+
],
|
3177 |
+
max_tokens=1000,
|
3178 |
+
temperature=0.5,
|
3179 |
+
top_p=1.0,
|
3180 |
+
frequency_penalty=0.5,
|
3181 |
+
presence_penalty=0.0
|
3182 |
+
)
|
3183 |
+
|
3184 |
+
# Extracting the SWOT analysis content from the response
|
3185 |
+
swot_analysis_content = response_swot.choices[0].message['content']
|
3186 |
+
|
3187 |
+
return swot_analysis_content
|
3188 |
+
|
3189 |
def evaluate_emission_sustainability_report(all_answers, score):
|
3190 |
"""Generates an Emission Sustainability report based on responses to a questionnaire."""
|
3191 |
extracted_data = extract_data(all_answers)
|
|
|
3228 |
|
3229 |
try:
|
3230 |
response = openai.ChatCompletion.create(
|
3231 |
+
model="gpt-3.5-turbo-16k",
|
3232 |
messages=[
|
3233 |
{"role": "system", "content": "Analyze the data and provide comprehensive insights and recommendations."},
|
3234 |
{"role": "user", "content": prompt}
|
|
|
3306 |
additional_context = f"Provide a detailed emission sustainability strategy using context data from the above company info and in responses to the emission sustainability assessment."
|
3307 |
# Assuming you have an API call here to generate a response based on the prompt
|
3308 |
response = openai.ChatCompletion.create(
|
3309 |
+
model="gpt-3.5-turbo-16k",
|
3310 |
messages=[
|
3311 |
{"role": "assistant", "content": "You are an emission sustainability strategy advisor."},
|
3312 |
{"role": "user", "content": prompt},
|
|
|
3423 |
|
3424 |
st.markdown(evaluate_emission_sustainability_practice(score, answers_df), unsafe_allow_html=True)
|
3425 |
|
3426 |
+
swot_analysis_content = generate_swot_analysis(company_data)
|
3427 |
+
#st.subheader("Energy Sustainability Strategy")
|
3428 |
+
st.subheader("Company SWOT Report")
|
3429 |
+
st.write(swot_analysis_content)
|
3430 |
+
|
3431 |
strategy = get_emission_sustainability_strategy(all_answers, company_data)
|
3432 |
#strategy = get_energy_sustainability_advice(strategy, company_data)
|
3433 |
report = evaluate_emission_sustainability_report(all_answers, score)
|
|
|
3492 |
API_KEY = "XXtYmhThBssK41ufq2JJOA"
|
3493 |
# Define headers for the API call
|
3494 |
headers = {
|
3495 |
+
"Authorization": f"Bearer {API_KEY}",
|
3496 |
+
"Content-Type": "application/json"
|
3497 |
}
|
3498 |
|
3499 |
# Streamlit UI
|
|
|
3557 |
|
3558 |
# List of sample IATA Codes
|
3559 |
iata_samples = [
|
3560 |
+
{
|
3561 |
+
"departure_airport": "SFO",
|
3562 |
+
"destination_airport": "YYZ"
|
3563 |
+
},
|
3564 |
+
{
|
3565 |
+
"departure_airport": "YYZ",
|
3566 |
+
"destination_airport": "SFO"
|
3567 |
+
}
|
3568 |
]
|
3569 |
|
3570 |
|
3571 |
|
3572 |
# Dropdown for Departure Airport
|
3573 |
+
#departure_airport = [sample["departure_airport"] for sample in iata_samples]
|
3574 |
+
#departure_airport = st.selectbox("Departure Airport (IATA Code)", departure_airport_options, key='departure_airport')
|
3575 |
+
departure_airport = "SFO"
|
3576 |
+
destination_airport = "YYZ"
|
3577 |
# Dropdown for Destination Airport
|
3578 |
# Filter destinations based on selected departure airport
|
3579 |
+
#destination_airport = [sample["destination_airport"] for sample in iata_samples if sample["departure_airport"] == departure_airport]
|
3580 |
+
#destination_airport = st.selectbox("Destination Airport (IATA Code)", destination_airport_options, key='destination_airport')
|
3581 |
|
3582 |
+
# Simplified CO2 Emission Coefficients (in gCO2 per unit)
|
3583 |
COEFFICIENTS = {
|
3584 |
+
"diesel": 2640, # gCO2 per liter
|
3585 |
+
"gasoline": 2392, # gCO2 per liter
|
3586 |
+
"natural_gas": 1870, # gCO2 per cubic meter
|
3587 |
+
"electricity": 0, # gCO2 per kWh (placeholder, actual value varies)
|
3588 |
}
|
3589 |
|
3590 |
fuel_source_units = {
|
3591 |
+
"diesel": ["gallons", "liters", "btu"],
|
3592 |
+
"gasoline": ["gallons", "liters", "btu"],
|
3593 |
+
"natural_gas": ["btu", "mcf", "therms"],
|
3594 |
+
#"electricity": ["kWh", "btu"],
|
3595 |
}
|
3596 |
|
3597 |
def calculate_emissions(fuel_type, fuel_unit, fuel_value):
|
3598 |
+
# Conversion constants to standardize units to liters or cubic meters
|
3599 |
+
unit_conversion = {
|
3600 |
+
"gallons": 3.78541, # 1 gallon to liters
|
3601 |
+
"mcf": 28.3168, # 1 mcf to cubic meters
|
3602 |
+
"therms": 2.83168, # 1 therm to cubic meters
|
3603 |
+
"btu": 0.000001 # Placeholder for BTU conversion, actual value depends on fuel type.
|
3604 |
+
}
|
3605 |
|
3606 |
+
# Specific BTU conversions to liters equivalent for each fuel type
|
3607 |
+
btu_conversion = {
|
3608 |
+
"diesel": 0.000065,
|
3609 |
+
"gasoline": 0.000074,
|
3610 |
+
"natural_gas": 0.000036, # Approximated value for natural gas
|
3611 |
+
}
|
3612 |
|
3613 |
+
# Adjust BTU conversion based on fuel type
|
3614 |
+
if fuel_unit == "btu":
|
3615 |
+
unit_conversion["btu"] = btu_conversion.get(fuel_type, 0.000001)
|
3616 |
|
3617 |
+
converted_value = fuel_value * unit_conversion.get(fuel_unit, 1)
|
3618 |
|
3619 |
+
return COEFFICIENTS.get(fuel_type, 0) * converted_value
|
3620 |
|
3621 |
# User Interface Simplification
|
3622 |
#st.write("**Fuel Combustion CO2 Emissions Calculator**")
|
3623 |
st.subheader("8. Fuel Combustion Emissions")
|
3624 |
# Reduced list of selectable fuel sources
|
3625 |
+
selected_fuel_sources = st.multiselect("Choose Fuel Source", ["diesel", "gasoline", "natural_gas"], key='fuel_source')
|
3626 |
+
|
3627 |
+
# Initialize an empty dictionary to store results
|
3628 |
+
inputs = {}
|
3629 |
|
3630 |
total_emissions = 0
|
3631 |
|
3632 |
for fuel_source in selected_fuel_sources:
|
3633 |
+
st.write(f"### {fuel_source} Emissions")
|
3634 |
+
|
3635 |
+
# Set the unit options based on the selected fuel source
|
3636 |
+
fuel_source_unit = st.selectbox(f"Unit of {fuel_source}", fuel_source_units[fuel_source], key=f'unit_{fuel_source}')
|
3637 |
|
3638 |
+
# Input for fuel quantity
|
3639 |
+
fuel_source_value = st.number_input(f"Amount of {fuel_source}", min_value=0.1, value=2.0, step=0.1, key=f'value_{fuel_source}')
|
3640 |
|
3641 |
+
# Calculate and display the emissions
|
3642 |
+
emission = calculate_emissions(fuel_source, fuel_source_unit, fuel_source_value)
|
3643 |
+
st.write(f"CO2 emissions for {fuel_source}: {emission:.2f} grams")
|
3644 |
|
3645 |
+
total_emissions += emission
|
|
|
|
|
3646 |
|
|
|
3647 |
|
3648 |
# Button to trigger the calculations
|
3649 |
if st.button("Calculate Carbon Emission"):
|
3650 |
+
with st.spinner("Calculating..."):
|
3651 |
|
3652 |
+
#results = {} # Initialize an empty dictionary to store results
|
3653 |
|
3654 |
+
# Electricity API Call
|
3655 |
+
payload_electricity = {
|
3656 |
+
"type": "electricity",
|
3657 |
+
"electricity_unit": electricity_unit,
|
3658 |
+
"electricity_value": electricity_value,
|
3659 |
+
"country": country
|
3660 |
+
}
|
3661 |
+
response_electricity = requests.post(API_URL, json=payload_electricity, headers=headers)
|
3662 |
+
if response_electricity.status_code == 201:
|
3663 |
+
results["Electricity"] = response_electricity.json().get("data", {}).get("attributes", {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3664 |
else:
|
3665 |
+
results["Electricity Error"] = f"Error: {response_electricity.status_code} - {response_electricity.text}"
|
3666 |
+
|
3667 |
+
# Vehicle API Call
|
3668 |
+
if vehicle_model_id: # Only make the API call if a vehicle_model_id is provided
|
3669 |
+
payload_vehicle = {
|
3670 |
+
"type": "vehicle",
|
3671 |
+
"distance_unit": distance_unit_vehicle,
|
3672 |
+
"distance_value": distance_value_vehicle,
|
3673 |
+
"vehicle_model_id": vehicle_model_id
|
3674 |
+
}
|
3675 |
+
response_vehicle = requests.post(API_URL, json=payload_vehicle, headers=headers)
|
3676 |
+
if response_vehicle.status_code == 201:
|
3677 |
+
results["Vehicle"] = response_vehicle.json().get("data", {}).get("attributes", {})
|
3678 |
+
else:
|
3679 |
+
results["Vehicle Error"] = f"Error: {response_vehicle.status_code} - {response_vehicle.text}"
|
3680 |
+
|
3681 |
+
# Flight API Call
|
3682 |
+
payload_flight = {
|
3683 |
+
"type": "flight",
|
3684 |
+
"passengers": passengers,
|
3685 |
+
"legs": [
|
3686 |
+
{"departure_airport": departure_airport, "destination_airport": destination_airport}
|
3687 |
+
]
|
3688 |
+
}
|
3689 |
+
response_flight = requests.post(API_URL, json=payload_flight, headers=headers)
|
3690 |
+
if response_flight.status_code == 201:
|
3691 |
+
results["Flight"] = response_flight.json().get("data", {}).get("attributes", {})
|
3692 |
+
else:
|
3693 |
+
results["Flight Error"] = f"Error: {response_flight.status_code} - {response_flight.text}"
|
3694 |
+
|
3695 |
+
data_for_df = []
|
3696 |
+
for key, value in results.items():
|
3697 |
+
if not key.endswith("_error"):
|
3698 |
+
try:
|
3699 |
+
data_for_df.append((key, value['carbon_g']))
|
3700 |
+
except TypeError:
|
3701 |
+
st.error(f"Unexpected value type for key: {key}. Value: {value}")
|
3702 |
+
|
3703 |
+
st.subheader("Carbon Emission Visual Analysis")
|
3704 |
+
df = pd.DataFrame(data_for_df, columns=["Segment", "Emissions (g)"])
|
3705 |
+
st.bar_chart(df.set_index("Segment"), use_container_width=True)
|
3706 |
+
#pie_chart_data = df.set_index("Segment")
|
3707 |
+
#st.pyplot(pie_chart_data.plot.pie(y='Emissions (g)', autopct='%1.1f%%', legend=False))
|
3708 |
+
# Set the index of your dataframe to 'Segment' for the pie chart
|
3709 |
+
pie_chart_data = df.set_index("Segment")
|
3710 |
+
|
3711 |
+
# Create a pie chart as a Figure object
|
3712 |
+
fig, ax = plt.subplots()
|
3713 |
+
ax.pie(pie_chart_data['Emissions (g)'], labels=pie_chart_data.index, autopct='%1.1f%%')
|
3714 |
+
|
3715 |
+
# Hide the legend if you don't want it
|
3716 |
+
ax.legend().set_visible(False)
|
3717 |
+
|
3718 |
+
# Display the pie chart in Streamlit
|
3719 |
+
st.pyplot(fig)
|
3720 |
+
|
3721 |
+
st.subheader("Table of Emission Factors")
|
3722 |
+
st.table(COEFFICIENTS)
|
3723 |
+
|
3724 |
+
st.subheader("Emission Reduction Goals Visualization")
|
3725 |
+
|
3726 |
+
# Use the total calculated emissions as the baseline
|
3727 |
+
total_emissions = df["Emissions (g)"].sum()
|
3728 |
+
|
3729 |
+
# Assuming the goal is zero emissions (100% reduction)
|
3730 |
+
goal_emissions = 0
|
3731 |
+
|
3732 |
+
# Calculate the emissions after the desired reduction target is applied
|
3733 |
+
emissions_after_reduction = total_emissions * (1 - (reduction_target / 100))
|
3734 |
+
|
3735 |
+
# Create a bar chart to compare current and post-reduction emissions
|
3736 |
+
reduction_data = {
|
3737 |
+
"Emission Type": ["Current Emissions", "Emissions After Target"],
|
3738 |
+
"Amount": [total_emissions, emissions_after_reduction]
|
3739 |
+
}
|
3740 |
+
df_reduction = pd.DataFrame(reduction_data)
|
3741 |
+
st.bar_chart(df_reduction.set_index("Emission Type"))
|
3742 |
+
|
3743 |
+
# Calculate the current progress
|
3744 |
+
current_progress = reduction_target / 100
|
3745 |
+
|
3746 |
+
# Display a label indicating the goal above the progress bar
|
3747 |
+
st.markdown(f"### Progress Towards Reduction Target ({reduction_target}% goal)")
|
3748 |
+
|
3749 |
+
# Visualize the progress with a progress bar
|
3750 |
+
st.progress(current_progress)
|
3751 |
+
|
3752 |
+
|
3753 |
+
# Textual description of the reduction progress
|
3754 |
+
st.markdown(f"The reduction target is set to **{reduction_target}%**.")
|
3755 |
+
st.markdown(f"With current emissions at **{total_emissions} g**, the target after reduction is **{emissions_after_reduction} g**.")
|
3756 |
+
st.markdown(f"To reach the goal of zero emissions, a further reduction of **{total_emissions - emissions_after_reduction} g** is needed.")
|
3757 |
+
|
3758 |
+
st.subheader("Emission Reduction Goals Visualization")
|
3759 |
+
|
3760 |
+
# Constants
|
3761 |
+
price_per_ton_CO2 = 20 # $20 per ton of CO2
|
3762 |
+
conversion_factor = 1e6 # 1,000,000 grams in a ton
|
3763 |
+
transmission_factor = 0.8
|
3764 |
+
reduction_target = reduction_target # Example reduction target percentage
|
3765 |
+
total_emissions = total_emissions # Example total emissions in grams
|
3766 |
+
|
3767 |
+
# Assuming two reduction targets: a specific target and 100%
|
3768 |
+
reduction_targets = set([reduction_target, 100])
|
3769 |
+
|
3770 |
+
# Lists to store the results
|
3771 |
+
money_earned_list = []
|
3772 |
+
|
3773 |
+
# Check if we have two distinct reduction targets
|
3774 |
+
if len(reduction_targets) != 2:
|
3775 |
+
raise ValueError("Reduction targets must be two distinct values.")
|
3776 |
+
|
3777 |
+
reduction_targets_sorted = []
|
3778 |
+
|
3779 |
+
# Calculate the money earned for each reduction target
|
3780 |
+
for target in sorted(reduction_targets):
|
3781 |
+
emissions_after_reduction = total_emissions * (1 - (target / 100))
|
3782 |
+
emissions_reduced = total_emissions - emissions_after_reduction
|
3783 |
+
emissions_reduced_in_tons = emissions_reduced / conversion_factor
|
3784 |
+
money_earned = emissions_reduced_in_tons * price_per_ton_CO2 * transmission_factor
|
3785 |
+
money_earned_list.append(money_earned)
|
3786 |
+
reduction_targets_sorted.append(target)
|
3787 |
+
|
3788 |
+
money_earned_target = money_earned_list[0] # For the specific reduction target
|
3789 |
+
money_earned_total = money_earned_list[1] # For total reduction
|
3790 |
+
|
3791 |
+
# Create DataFrame for plotting
|
3792 |
+
data = {"Reduction Target (%)": reduction_targets_sorted, "Money Earned ($)": money_earned_list}
|
3793 |
+
df_money = pd.DataFrame(data)
|
3794 |
+
|
3795 |
+
# Using st.markdown to display the dynamic message in a Streamlit app
|
3796 |
+
# Displaying the assumptions
|
3797 |
+
st.markdown(f"Assuming a transmission factor of **{transmission_factor}** and a price of **${price_per_ton_CO2}** per ton of CO2,")
|
3798 |
+
|
3799 |
+
# Displaying the potential gain with the specified reduction target
|
3800 |
+
st.markdown(f"your company is likely to gain an amount of **${money_earned_target:.2f}** with a **{reduction_target}%** reduction target,")
|
3801 |
+
|
3802 |
+
# Displaying the potential gain with total carbon reduction
|
3803 |
+
st.markdown(f"and **${money_earned_total:.2f}** with total carbon reduction.")
|
3804 |
+
|
3805 |
+
# Displaying the advisory note
|
3806 |
+
st.markdown("This is an assumption, and you are advised to look into carbon-cash exchange models for more accurate estimations.")
|
3807 |
+
|
3808 |
+
# Plotting the data
|
3809 |
+
plt.figure(figsize=(10, 6))
|
3810 |
+
plt.plot(df_money["Reduction Target (%)"], df_money["Money Earned ($)"], marker='o')
|
3811 |
+
plt.title("Potential Money Earned by Reducing Carbon Emissions")
|
3812 |
+
plt.xlabel("Reduction Target (%)")
|
3813 |
+
plt.ylabel("Money Earned ($)")
|
3814 |
+
plt.grid(True)
|
3815 |
+
# Using st.pyplot() to display the plot in Streamlit
|
3816 |
+
st.pyplot(plt)
|
3817 |
+
|
3818 |
+
|
3819 |
+
responses = {
|
3820 |
+
"shipping_routes": {
|
3821 |
+
"average_distance": "average_ship_distance",
|
3822 |
+
"common_ship_type": "most_common_ship_type",
|
3823 |
+
},
|
3824 |
+
"warehousing": {
|
3825 |
+
"energy_source": "warehouse_energy_source",
|
3826 |
+
"size": "warehouse_size",
|
3827 |
+
"insulation": "warehouse_insulation",
|
3828 |
+
},
|
3829 |
+
"packaging": {
|
3830 |
+
"material": "packaging_material",
|
3831 |
+
},
|
3832 |
+
"fleet_management": {
|
3833 |
+
"percentage_electric": "percentage_electric_vehicles",
|
3834 |
+
"average_age": "average_age_of_ships",
|
3835 |
+
},
|
3836 |
+
"vehicular_emissions": {
|
3837 |
+
"distance_unit": "distance_unit_vehicle",
|
3838 |
+
"distance_value": "distance_value_vehicle",
|
3839 |
+
"model_id": "vehicle_model_id",
|
3840 |
+
},
|
3841 |
+
"fuel_combustion_emissions": {
|
3842 |
+
"selected_fuel_sources": "selected_fuel_sources",
|
3843 |
+
"total_emissions": "total_emissions",
|
3844 |
+
},
|
3845 |
+
"emission_reduction_goals": {
|
3846 |
+
# Initialize with empty strings or appropriate placeholders
|
3847 |
+
"current_emissions": "",
|
3848 |
+
"emissions_after_target": "",
|
3849 |
+
"reduction_target": "",
|
3850 |
+
},
|
3851 |
}
|
|
|
|
|
|
|
|
|
|
|
3852 |
|
3853 |
+
#- Current total emissions and the goal of reaching zero emissions
|
3854 |
+
#- Reduction target for emissions
|
3855 |
+
#- Fuel combustion emissions
|
3856 |
+
#- Electricity use in port operations
|
3857 |
+
#- Fleet management practices
|
3858 |
+
#- Shipping route efficiency
|
3859 |
+
|
3860 |
+
inputs = {
|
3861 |
+
"Average Shipping Distance (km)": average_ship_distance,
|
3862 |
+
"Most Common Ship Type": most_common_ship_type,
|
3863 |
+
"Primary Warehouse Energy Source": warehouse_energy_source,
|
3864 |
+
"Total Warehouse Space (sq.m)": warehouse_size,
|
3865 |
+
"Warehouse Insulation Quality": warehouse_insulation,
|
3866 |
+
"Primary Packaging Material": packaging_material,
|
3867 |
+
"Fleet Electric Vehicles (%)": percentage_electric_vehicles,
|
3868 |
+
"Average Age of Ships (years)": average_age_of_ships,
|
3869 |
+
"Port Operations Electricity Unit": electricity_unit,
|
3870 |
+
"Port Operations Electricity Consumption": electricity_value,
|
3871 |
+
"Vehicle Distance Unit": distance_unit_vehicle,
|
3872 |
+
"Vehicle Distance Traveled": distance_value_vehicle,
|
3873 |
+
"Emission Reduction Target (%)": reduction_target,
|
3874 |
+
"Total Annual Carbon Emissions (grams)": total_emissions
|
3875 |
+
}
|
3876 |
+
# Calculate the emissions after the desired reduction target is applied
|
3877 |
+
emissions_after_reduction = total_emissions * (1 - (reduction_target / 100))
|
3878 |
|
3879 |
+
# Update the inputs dictionary with the new key-value pair
|
3880 |
+
inputs.update({
|
3881 |
+
f"Emissions After {reduction_target}% Reduction Target (grams)": emissions_after_reduction
|
3882 |
+
})
|
3883 |
|
3884 |
+
#st.write(inputs)
|
|
|
3885 |
|
3886 |
+
# Formulate the prompt for GPT
|
3887 |
+
# Constructing the prompt based on input parameters
|
3888 |
+
report_prompt = f"""
|
3889 |
+
Detailed Carbon Emission Analysis Report:
|
3890 |
|
3891 |
+
- Total annual emissions: {inputs["Total Annual Carbon Emissions (grams)"]} grams
|
3892 |
+
- Emission reduction target: {inputs["Emission Reduction Target (%)"]}%
|
3893 |
+
- Impact of {inputs["Most Common Ship Type"]} and its average age ({inputs["Average Age of Ships (years)"]} years) on fuel combustion emissions.
|
3894 |
+
- Electricity consumption in port operations: {inputs["Port Operations Electricity Consumption"]} {inputs["Port Operations Electricity Unit"]}
|
3895 |
+
- Fleet management practices: {inputs["Fleet Electric Vehicles (%)"]} electric vehicles in the fleet.
|
3896 |
+
- Average shipping distance efficiency: {inputs["Average Shipping Distance (km)"]} km
|
3897 |
|
3898 |
+
Please generate a detailed report analyzing the current carbon emissions scenario, considering the mentioned parameters, and propose recommendations to effectively reduce the organization's carbon footprint in shipping and logistics. The report should encompass comprehensive insights, statistical analysis, and a clear assessment of potential strategies and their impact on carbon reduction. Consider feasibility, cost-effectiveness, and alignment with industry best practices.
|
3899 |
+
"""
|
3900 |
|
3901 |
+
# OpenAI API call for the response
|
3902 |
+
response = openai.ChatCompletion.create(
|
3903 |
+
model="gpt-3.5-turbo-16k",
|
3904 |
+
messages=[
|
3905 |
+
{"role": "assistant", "content": "You are a carbon management and reduction strategist."},
|
3906 |
+
{"role": "system", "content": "Provide report based on the carbon emission data."},
|
3907 |
+
{"role": "user", "content": report_prompt}
|
3908 |
+
],
|
3909 |
+
max_tokens=700,
|
3910 |
+
temperature=0.5,
|
3911 |
+
top_p=1.0,
|
3912 |
+
frequency_penalty=0.5,
|
3913 |
+
presence_penalty=0.0
|
3914 |
+
)
|
3915 |
|
|
|
|
|
3916 |
|
3917 |
+
# Constructing a prompt for SWOT analysis based on provided data
|
3918 |
+
swot_analysis_prompt = f"""
|
3919 |
+
Strengths, Weaknesses, Opportunities, Threats (SWOT) Analysis:
|
3920 |
+
|
3921 |
+
Strengths:
|
3922 |
+
Strengths Analysis:
|
3923 |
+
The company's carbon activities show several positive attributes:
|
3924 |
+
1. Efficient Shipping: Utilizing {inputs["Average Shipping Distance (km)"]} km as the average shipping distance showcases efficiency in transportation.
|
3925 |
+
2. Electric Vehicles: With {inputs["Fleet Electric Vehicles (%)"]} of the fleet being electric, it exhibits a commitment to eco-friendly transportation.
|
3926 |
+
3. Warehouse Insulation: The warehouse insulation quality, rated as {inputs["Warehouse Insulation Quality"]}, contributes positively to energy conservation.
|
3927 |
+
|
3928 |
+
Weaknesses:
|
3929 |
+
Weaknesses Analysis:
|
3930 |
+
Despite positive aspects, the company's carbon activities display areas needing improvement:
|
3931 |
+
1. Fuel-Dependent Ships: The average age of ships ({inputs["Average Age of Ships (years)"]} years) and the prevalent ship type ({inputs["Most Common Ship Type"]}) might indicate higher fuel combustion emissions.
|
3932 |
+
2. Warehouse Energy Source: Dependency on {inputs["Primary Warehouse Energy Source"]} as the primary energy source might contribute to carbon emissions.
|
3933 |
+
3. Packaging Material Impact: The choice of {inputs["Primary Packaging Material"]} might have environmental implications.
|
3934 |
+
|
3935 |
+
Opportunities:
|
3936 |
+
Opportunities Analysis:
|
3937 |
+
Exploring areas for growth or improvement in the company's carbon activities:
|
3938 |
+
1. Renewable Energy Adoption: Consider adopting renewable sources like solar or wind power for warehouses.
|
3939 |
+
2. Fleet Upgrade: Investing in newer, more fuel-efficient ship types can significantly reduce emissions.
|
3940 |
+
3. Sustainable Packaging: Explore and adopt environmentally friendly packaging alternatives.
|
3941 |
+
|
3942 |
+
Threats:
|
3943 |
+
Threats Analysis:
|
3944 |
+
Identifying potential risks or threats affecting the company's carbon activities:
|
3945 |
+
1. Regulatory Changes: Anticipate changes in environmental regulations impacting carbon emissions in shipping and logistics.
|
3946 |
+
2. Rising Energy Costs: Potential increases in electricity prices may impact operational expenses.
|
3947 |
+
3. Market Shifts: Changes in market dynamics may affect shipping route efficiency or demand.
|
3948 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3949 |
|
3950 |
+
# OpenAI API call for SWOT analysis
|
3951 |
+
response_swot = openai.ChatCompletion.create(
|
3952 |
+
model="gpt-3.5-turbo",
|
3953 |
+
messages=[
|
3954 |
+
{"role": "assistant", "content": "You are analyzing the company's carbon activities."},
|
3955 |
+
{"role": "system", "content": "Conduct a SWOT analysis based on the provided data."},
|
3956 |
+
{"role": "user", "content": swot_analysis_prompt}
|
3957 |
+
],
|
3958 |
+
max_tokens=1000,
|
3959 |
+
temperature=0.5,
|
3960 |
+
top_p=1.0,
|
3961 |
+
frequency_penalty=0.5,
|
3962 |
+
presence_penalty=0.0
|
3963 |
+
)
|
3964 |
|
|
|
|
|
|
|
|
|
|
|
3965 |
|
|
|
|
|
|
|
3966 |
|
|
|
3967 |
|
3968 |
+
# Constructing the prompt for the Carbon Reduction Strategy Advisor
|
3969 |
+
strategy_prompt = f"""
|
3970 |
+
Carbon Reduction Strategy Advisor:
|
|
|
|
|
|
|
|
|
3971 |
|
3972 |
+
Given the specific parameters provided for carbon emissions in the shipping and logistics domain:
|
|
|
3973 |
|
3974 |
+
- Total annual emissions: {inputs["Total Annual Carbon Emissions (grams)"]} grams
|
3975 |
+
- Emission reduction target: {inputs["Emission Reduction Target (%)"]}% reduction target
|
3976 |
+
- Fuel combustion emissions related to {inputs["Most Common Ship Type"]} with an average age of {inputs["Average Age of Ships (years)"]} years.
|
3977 |
+
- Electricity use in port operations: {inputs["Port Operations Electricity Consumption"]} {inputs["Port Operations Electricity Unit"]} used in port operations.
|
3978 |
+
- Fleet management practices: {inputs["Fleet Electric Vehicles (%)"]} of fleet being electric vehicles.
|
3979 |
+
- Shipping route efficiency: Average shipping distance is {inputs["Average Shipping Distance (km)"]} km.
|
3980 |
+
|
3981 |
+
The objective is to achieve significant carbon reduction while considering cost-effectiveness and industry best practices.
|
3982 |
+
|
3983 |
+
Please provide detailed strategies, innovative approaches, and practical steps to significantly reduce carbon emissions in the shipping and logistics operations. Focus on actionable advice, implementation frameworks, and potential challenges to consider when adopting these strategies.
|
3984 |
+
"""
|
3985 |
+
|
3986 |
+
# OpenAI API call for carbon reduction strategies
|
3987 |
+
response_strategies = openai.ChatCompletion.create(
|
3988 |
+
model="gpt-3.5-turbo",
|
3989 |
+
messages=[
|
3990 |
+
{"role": "assistant", "content": "You are a carbon management and reduction strategist."},
|
3991 |
+
{"role": "system", "content": "Provide strategies to achieve significant carbon reduction."},
|
3992 |
+
{"role": "user", "content": strategy_prompt}
|
3993 |
+
],
|
3994 |
+
max_tokens=1000,
|
3995 |
+
temperature=0.5,
|
3996 |
+
top_p=1.0,
|
3997 |
+
frequency_penalty=0.5,
|
3998 |
+
presence_penalty=0.0
|
3999 |
+
)
|
4000 |
+
|
4001 |
+
|
4002 |
+
# Display the strategies to the user or use it as needed in your application
|
4003 |
+
# strategies_content contains the generated strategies for carbon reduction
|
4004 |
+
|
4005 |
+
swot_result = response_swot.choices[0].message['content']
|
4006 |
+
|
4007 |
+
# Display the advice to the user
|
4008 |
+
st.subheader("Carbon Swot Analysis")
|
4009 |
+
st.write(swot_result)
|
4010 |
+
st.download_button(
|
4011 |
+
label="Download SWOT Analysis",
|
4012 |
+
data=swot_result,
|
4013 |
+
file_name='SWOT_Anlysis.txt',
|
4014 |
+
mime='text/txt',
|
4015 |
+
key="download_SWOT_button", # Unique key for this button
|
4016 |
+
)
|
4017 |
+
|
4018 |
+
# Extracting the advice content from the response
|
4019 |
+
advice_content = response.choices[0].message['content']
|
4020 |
+
|
4021 |
+
# Display the advice to the user
|
4022 |
+
st.subheader("Sustainability Report")
|
4023 |
+
st.write(advice_content)
|
4024 |
+
st.download_button(
|
4025 |
+
label="Download Sustainability advice",
|
4026 |
+
data=advice_content,
|
4027 |
+
file_name='sustainability_advice.txt',
|
4028 |
+
mime='text/txt',
|
4029 |
+
key="download_advice_button", # Unique key for this button
|
4030 |
+
)
|
4031 |
+
|
4032 |
+
# Extracting the strategies content from the response
|
4033 |
+
strategies_content = response_strategies.choices[0].message['content']
|
4034 |
+
|
4035 |
+
# Display the advice to the user
|
4036 |
+
st.subheader("Carbon Reduction Strategy")
|
4037 |
+
st.write(strategies_content)
|
4038 |
+
st.download_button(
|
4039 |
+
label="Download Sustainability strategy",
|
4040 |
+
data=strategies_content,
|
4041 |
+
file_name='sustainability_strategy.txt',
|
4042 |
+
mime='text/txt',
|
4043 |
+
key="download_strategy_button", # Unique key for this button
|
4044 |
+
)
|
4045 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4046 |
|
4047 |
# Display a disclaimer message
|
4048 |
st.warning("Disclaimer: The carbon emission calculations provided here are based on certain assumptions and data sources. While we strive to provide accurate estimates, please be aware that the results should be considered as approximate. For the most accurate carbon emissions assessment, we recommend testing with globally accepted values and results.")
|
|
|
4052 |
*Powered by Streamlit, CarbonInterface API, and OpenAI.*
|
4053 |
""")
|
4054 |
|
4055 |
+
|
4056 |
def page7():
|
4057 |
# Load and set OpenAI API key from file
|
4058 |
os.environ["OPENAI_API_KEY"] = open("key.txt", "r").read().strip("\n")
|