Kunal commited on
Commit
42c47cc
·
1 Parent(s): 8af29c0

updated Readme

Browse files
Files changed (2) hide show
  1. README.md +81 -1
  2. app.py +7 -2
README.md CHANGED
@@ -10,4 +10,84 @@ pinned: false
10
  short_description: Gives Carbon Footprint Score for products description or url
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  short_description: Gives Carbon Footprint Score for products description or url
11
  ---
12
 
13
+ # Enviromental Impact Analyzer
14
+ This project, "Environmental Impact Analyzer," is a Gradio-based application designed to assess the environmental footprint of products. Users can input either a product description or a URL to a product page, and the application will extract relevant information, calculate its carbon footprint, generate an environmental sustainability score, and provide actionable recommendations for improvement.
15
+
16
+ ---
17
+
18
+ ## Features:
19
+ - **Product Information Extraction:** Automatically extracts key environmental factors from text descriptions or web pages (via URL scraping).
20
+ - **Carbon Footprint Calculation:** Integrates with the Climatiq API to estimate the carbon emissions associated with the product's manufacturing and transportation.
21
+ - **Environmental Scoring:** Leverages advanced Large Language Models (LLMs) to generate a comprehensive sustainability score (0-100) based on multiple environmental criteria.
22
+ - **Improvement Recommendations:** Provides specific and actionable suggestions to reduce the product's environmental impact.
23
+ **Intuitive Gradio Interface:** Offers an easy-to-use web interface for seamless interaction.
24
+
25
+ ---
26
+
27
+ ## How It Works
28
+ The core of the Environmental Impact Analyzer is built using **LangGraph**, enabling a stateful, multi-step agentic workflow:
29
+
30
+ 1. **Input Classification:** Determines if the user input is a direct product description or a URL.
31
+ 2. **Information Extraction:**
32
+ * If a URL, it **scrapes** the product information from the web page.
33
+ * If a description, it directly processes the provided text.
34
+ * An LLM (`deepseek-ai/DeepSeek-R1`) is then used to **extract structured environmental data** (e.g., material composition, manufacturing location, weight, transport distance, recyclability).
35
+ 3. **Carbon Footprint Calculation:** The extracted data is sent to the **Climatiq API** to calculate the estimated carbon footprint (in kg CO2e) based on factors like materials and transportation.
36
+ 4. **Environmental Scoring & Recommendations:**
37
+ * An LLM (`meta-llama/Meta-Llama-3.1-70B-Instruct`) evaluates the extracted data and carbon footprint.
38
+ * It generates an **overall environmental score** (0-100), considering factors like carbon emissions, material sustainability, manufacturing practices, transport, longevity, and end-of-life. The scoring is calibrated to recognize positive environmental efforts.
39
+ * It also provides a **category breakdown** of the score and **actionable recommendations** for improving the product's environmental impact.
40
+
41
+ **Note:** You can also change the Models for your liking to increse Speed or more accuracy.but make sure hyperbolic supports it.
42
+
43
+ ---
44
+
45
+ ## Tech Stack
46
+
47
+ | Category | Technology | Purpose |
48
+ | :------------------ | :----------------------------------------- | :------------------------------------------------------------------- |
49
+ | **Framework** | Gradio | Building the interactive web user interface. |
50
+ | **Agentic Workflow**| LangGraph | Orchestrating multi-step agent logic and state management. |
51
+ | **LLM Integration** | Hugging Face Inference Client | Interacting with Large Language Models hosted on Hugging Face Hub. |
52
+ | **Core LLM** | `deepseek-ai/DeepSeek-R1` | Generates environmental scores, category breakdowns, and recommendations. |
53
+ | **External APIs** | Climatiq API | Calculates carbon footprint based on product data. |
54
+ | **Web Scraping** | `requests`, `BeautifulSoup` (via `scrapper.py`) | Fetching and parsing HTML content from product URLs. |
55
+ | **Prompting** | `langchain.prompts.ChatPromptTemplate` | Structuring and templating LLM prompts for consistent input. |
56
+ | **Environment Mgt.**| `python-dotenv` | Loading environment variables from `.env` files for secure key management. |
57
+ | **Data Typing** | `typing`, `typing_extensions` (`TypedDict`) | Enhancing code readability and maintainability with type hints. |
58
+
59
+ ---
60
+
61
+ ## Setup and Installation
62
+
63
+ To run this project locally, follow these steps:
64
+
65
+ ### 1. Clone the Repository
66
+
67
+ ```bash
68
+ git clone [https://huggingface.co/spaces/Agents-MCP-Hackathon/Environmental-Impact-Analyzer](https://huggingface.co/spaces/Agents-MCP-Hackathon/Environmental-Impact-Analyzer)
69
+ cd Environmental-Impact-Analyzer
70
+ ```
71
+
72
+ ### 2. Create a Virtual Environment (Recommended)
73
+ ```bash
74
+ python -m venv .venv
75
+ # On Windows
76
+ .venv\Scripts\activate
77
+ # On macOS/Linux
78
+ source .venv/bin/activate
79
+ ```
80
+ ### 3. Install Dependencies
81
+ ```bash
82
+ pip install -r requirements.txt
83
+ ```
84
+ ### 4. 4. Configure Environment Variables
85
+ Create a .env file in the root directory of your project and add the following:
86
+ ```
87
+ HF_API_KEY="hf_YOUR_HUGGING_FACE_ACCESS_TOKEN"
88
+ CLIMATIQ_API_KEY="YOUR_CLIMATIQ_API_KEY"
89
+ ```
90
+ ### 5. Run the Application
91
+ ```bash
92
+ python app.py
93
+ ```
app.py CHANGED
@@ -84,7 +84,7 @@ def create_gradio_interface():
84
  with gr.Column(scale=2):
85
  # Input section
86
  product_input = gr.Textbox(
87
- label="Product Description",
88
  placeholder="e.g., Organic cotton t-shirt manufactured in India, packaged in recyclable materials...",
89
  lines=4,
90
  max_lines=8
@@ -101,7 +101,7 @@ def create_gradio_interface():
101
  with gr.Group():
102
  score_output = gr.Markdown(
103
  label="Environmental Score",
104
- value="Enter a product description and click analyze to see results."
105
  )
106
 
107
  status_output = gr.Markdown(
@@ -141,6 +141,11 @@ def create_gradio_interface():
141
  inputs=[product_input],
142
  label="Example Products to Analyze"
143
  )
 
 
 
 
 
144
 
145
  return interface
146
 
 
84
  with gr.Column(scale=2):
85
  # Input section
86
  product_input = gr.Textbox(
87
+ label="Product Description/URL",
88
  placeholder="e.g., Organic cotton t-shirt manufactured in India, packaged in recyclable materials...",
89
  lines=4,
90
  max_lines=8
 
101
  with gr.Group():
102
  score_output = gr.Markdown(
103
  label="Environmental Score",
104
+ value="Enter a product description/URL and click analyze to see results."
105
  )
106
 
107
  status_output = gr.Markdown(
 
141
  inputs=[product_input],
142
  label="Example Products to Analyze"
143
  )
144
+ gr.Markdown("""
145
+ **Note**: add the Following Secret Key to your environment variables:
146
+ - `HF_API_KEY` (Hugging Face API token) to access private models or higher rate limits.
147
+ - `CLIMATIQ_API_KEY` (Climatiq API token) for carbon footprint calculations.
148
+ """)
149
 
150
  return interface
151