Chittrarasu commited on
Commit
2e24d5b
·
1 Parent(s): f2c6a57

added Dockerfile

Browse files
Dockerfile ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.11 as the base image
2
+ FROM python:3.11
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+
7
+ # Copy all project files into the container
8
+ COPY . /app
9
+
10
+ # Install dependencies
11
+ RUN pip install --upgrade pip
12
+ RUN pip install -r requirement.txt
13
+
14
+ # Expose ports for FastAPI (8000) and Streamlit (8501)
15
+ EXPOSE 8000
16
+ EXPOSE 8501
17
+
18
+ # Start both FastAPI and Streamlit when the container runs
19
+ CMD ["sh", "-c", "uvicorn backend.main:app --host 0.0.0.0 --port 8000 & streamlit run frontend/app.py --server.port 8501 --server.address 0.0.0.0"]
README.md CHANGED
@@ -6,5 +6,4 @@ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
  ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
6
  sdk: docker
7
  pinned: false
8
  ---
9
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-referenceu
 
backend/logs/backend.log CHANGED
@@ -101,3 +101,13 @@
101
  2025-02-08 16:10:16,231 - INFO - Application shutdown complete.
102
  2025-02-08 16:10:16,236 - INFO - Finished server process [5408]
103
  2025-02-08 16:10:16,671 - INFO - Stopping reloader process [1920]
 
 
 
 
 
 
 
 
 
 
 
101
  2025-02-08 16:10:16,231 - INFO - Application shutdown complete.
102
  2025-02-08 16:10:16,236 - INFO - Finished server process [5408]
103
  2025-02-08 16:10:16,671 - INFO - Stopping reloader process [1920]
104
+ 2025-02-10 11:52:37,019 - INFO - CSV file loaded successfully.
105
+ 2025-02-10 11:52:37,108 - INFO - Data processing completed.
106
+ 2025-02-10 11:52:37,176 - INFO - Starting FastAPI application...
107
+ 2025-02-10 11:52:37,381 - INFO - Will watch for changes in these directories: ['C:\\chitu\\population_api\\backend']
108
+ 2025-02-10 11:52:37,399 - ERROR - [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
109
+ 2025-02-10 11:56:24,383 - INFO - CSV file loaded successfully.
110
+ 2025-02-10 11:56:24,468 - INFO - Data processing completed.
111
+ 2025-02-10 11:56:24,560 - INFO - Starting FastAPI application...
112
+ 2025-02-10 11:56:24,731 - INFO - Will watch for changes in these directories: ['C:\\chitu\\population_api\\backend']
113
+ 2025-02-10 11:56:24,754 - ERROR - [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
backend/service/__pycache__/population_pandas.cpython-313.pyc CHANGED
Binary files a/backend/service/__pycache__/population_pandas.cpython-313.pyc and b/backend/service/__pycache__/population_pandas.cpython-313.pyc differ
 
backend/service/population_pandas.py CHANGED
@@ -2,31 +2,39 @@ import pandas as pd
2
  # from backend.population_pandas import get_continents, get_continent_data
3
  from backend.logger import logger
4
 
5
- # Load the dataset
 
 
 
 
 
 
6
  try:
7
- df = pd.read_csv("data/world_population.csv")
8
- logger.info("CSV file loaded successfully.")
9
  except Exception as e:
10
- logger.error(f"Error loading CSV file: {e}")
11
-
12
- # Aggregate the data
13
- continent_stats = df.groupby("Continent").agg(
14
- Total_Countries=('Country', 'count'),
15
- Total_Population=('Population', 'sum'),
16
- Average_Population=('Population', 'mean'),
17
- Total_Area=('Area', 'sum'),
18
- max_population=('Population', 'max'),
19
- min_population=('Population', 'min'),
20
- Country_Max_Population=('Population', lambda x: df.loc[x.idxmax(), 'Country']),
21
- Country_Min_Population=('Population', lambda x: df.loc[x.idxmin(), 'Country'])
22
- ).reset_index()
23
-
24
- # Compute Population Density
25
- continent_stats["Population_Density"] = (
26
- continent_stats["Total_Population"] / continent_stats["Total_Area"]
27
- )
28
-
29
- logger.info("Data processing completed.")
 
 
30
 
31
  def get_continents():
32
  """Returns a list of all continents."""
@@ -43,3 +51,5 @@ def get_continent_data(continent):
43
  return {}
44
 
45
  return result.to_dict()
 
 
 
2
  # from backend.population_pandas import get_continents, get_continent_data
3
  from backend.logger import logger
4
 
5
+ import os
6
+
7
+ # file_path = os.path.join(os.path.dirname(__file__), "../../data/world_population.csv")
8
+ file_path = os.path.join(os.path.dirname(__file__), "../data/world_population.csv")
9
+ # file_path = os.path.abspath(file_path) # Convert to absolute path
10
+
11
+ file_path = os.path.abspath(file_path) # Convert to absolute path
12
  try:
13
+ df = pd.read_csv(file_path)
14
+ logger.info(f"CSV file loaded successfully from: {file_path}")
15
  except Exception as e:
16
+ logger.error(f"Error loading CSV file from {file_path}: {e}")
17
+ df = None # Prevent NameError if file loading fails
18
+
19
+ if df is not None:
20
+ # Perform the aggregations only if df is successfully loaded
21
+ continent_stats = df.groupby("Continent").agg(
22
+ Total_Countries=('Country', 'count'),
23
+ Total_Population=('Population', 'sum'),
24
+ Average_Population=('Population', 'mean'),
25
+ Total_Area=('Area', 'sum'),
26
+ max_population=('Population', 'max'),
27
+ min_population=('Population', 'min'),
28
+ Country_Max_Population=('Population', lambda x: df.loc[x.idxmax(), 'Country']),
29
+ Country_Min_Population=('Population', lambda x: df.loc[x.idxmin(), 'Country'])
30
+ ).reset_index()
31
+
32
+ # Compute Population Density
33
+ continent_stats["Population_Density"] = (
34
+ continent_stats["Total_Population"] / continent_stats["Total_Area"]
35
+ )
36
+
37
+ logger.info("Data processing completed.")
38
 
39
  def get_continents():
40
  """Returns a list of all continents."""
 
51
  return {}
52
 
53
  return result.to_dict()
54
+
55
+
requirement.txt ADDED
Binary file (2.42 kB). View file