devusman commited on
Commit
3034be5
·
1 Parent(s): 522f625

updated added datasets

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. Dockerfile +16 -3
  3. index.js +6 -6
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  node_modules
2
  dist/
3
- package-lock.json
 
 
1
  node_modules
2
  dist/
3
+ package-lock.json
4
+ data/
Dockerfile CHANGED
@@ -1,14 +1,26 @@
1
  # Use a stable and small Node.js image
2
  FROM node:18-alpine
3
 
 
 
 
4
  # Set the working directory inside the container
5
  WORKDIR /app
6
 
 
 
 
 
 
 
 
 
7
  # Copy package files and install dependencies first to leverage Docker's layer caching
8
- COPY package.json package-lock.json ./
9
- RUN npm install
 
10
 
11
- # Copy the rest of your application code
12
  COPY . .
13
 
14
  # Expose the port that Hugging Face Spaces expects.
@@ -16,4 +28,5 @@ COPY . .
16
  EXPOSE 7860
17
 
18
  # The command to start your Express server
 
19
  CMD ["node", "index.js"]
 
1
  # Use a stable and small Node.js image
2
  FROM node:18-alpine
3
 
4
+ # Install Git and Git LFS, which are required to clone from the Hugging Face Hub
5
+ RUN apk add --no-cache git git-lfs
6
+
7
  # Set the working directory inside the container
8
  WORKDIR /app
9
 
10
+ # Initialize Git LFS in the container environment
11
+ RUN git lfs install
12
+
13
+ # --- IMPORTANT STEP ---
14
+ # Clone your 'waliyan' dataset and place its contents into a local 'data' folder.
15
+ # The "--depth 1" flag makes the download faster by only getting the latest version.
16
+ RUN git clone --depth 1 https://huggingface.co/datasets/devusman/waliyan data
17
+
18
  # Copy package files and install dependencies first to leverage Docker's layer caching
19
+ COPY package.json package-lock.json* ./
20
+ # Use 'npm ci' for reproducible builds in production environments
21
+ RUN npm ci
22
 
23
+ # Copy the rest of your application code (index.js, views/, etc.)
24
  COPY . .
25
 
26
  # Expose the port that Hugging Face Spaces expects.
 
28
  EXPOSE 7860
29
 
30
  # The command to start your Express server
31
+ # Your code will now find the 'data' folder at /app/data
32
  CMD ["node", "index.js"]
index.js CHANGED
@@ -10,12 +10,12 @@ app.set('view engine', 'ejs');
10
  app.set('views', path.join(__dirname, 'views'));
11
 
12
  // Serve the dist directory as a static folder
13
- app.use('/api', express.static(path.join(__dirname, 'dist')));
14
 
15
  // Route to render the EJS testing page
16
  app.get('/', async (req, res) => {
17
  try {
18
- const provincesData = await fs.readFile(path.join(__dirname, 'dist', 'provinces.json'), 'utf8');
19
  const provinces = JSON.parse(provincesData);
20
  res.render('index', { provinces });
21
  } catch (error) {
@@ -27,7 +27,7 @@ app.get('/', async (req, res) => {
27
  // API endpoint for provinces
28
  app.get('/api/provinces', async (req, res) => {
29
  try {
30
- const data = await fs.readFile(path.join(__dirname, 'dist', 'provinces.json'), 'utf8');
31
  res.json(JSON.parse(data));
32
  } catch (error) {
33
  res.status(404).json({ error: 'Provinces not found' });
@@ -38,7 +38,7 @@ app.get('/api/provinces', async (req, res) => {
38
  app.get('/api/provinces/:provinceId/regencies', async (req, res) => {
39
  const { provinceId } = req.params;
40
  try {
41
- const data = await fs.readFile(path.join(__dirname, 'dist', provinceId, 'regencies.json'), 'utf8');
42
  res.json(JSON.parse(data));
43
  } catch (error) {
44
  res.status(404).json({ error: 'Regencies not found for this province' });
@@ -49,7 +49,7 @@ app.get('/api/provinces/:provinceId/regencies', async (req, res) => {
49
  app.get('/api/provinces/:provinceId/regencies/:regencyId/districts', async (req, res) => {
50
  const { provinceId, regencyId } = req.params;
51
  try {
52
- const data = await fs.readFile(path.join(__dirname, 'dist', provinceId, regencyId, 'district.json'), 'utf8');
53
  res.json(JSON.parse(data));
54
  } catch (error) {
55
  res.status(404).json({ error: 'Districts not found for this regency' });
@@ -60,7 +60,7 @@ app.get('/api/provinces/:provinceId/regencies/:regencyId/districts', async (req,
60
  app.get('/api/provinces/:provinceId/regencies/:regencyId/districts/:districtId/villages', async (req, res) => {
61
  const { provinceId, regencyId, districtId } = req.params;
62
  try {
63
- const data = await fs.readFile(path.join(__dirname, 'dist', provinceId, regencyId, districtId, 'subdistrict.json'), 'utf8');
64
  res.json(JSON.parse(data));
65
  } catch (error) {
66
  res.status(404).json({ error: 'Villages not found for this district' });
 
10
  app.set('views', path.join(__dirname, 'views'));
11
 
12
  // Serve the dist directory as a static folder
13
+ app.use('/api', express.static(path.join(__dirname, 'data')));
14
 
15
  // Route to render the EJS testing page
16
  app.get('/', async (req, res) => {
17
  try {
18
+ const provincesData = await fs.readFile(path.join(__dirname, 'data', 'provinces.json'), 'utf8');
19
  const provinces = JSON.parse(provincesData);
20
  res.render('index', { provinces });
21
  } catch (error) {
 
27
  // API endpoint for provinces
28
  app.get('/api/provinces', async (req, res) => {
29
  try {
30
+ const data = await fs.readFile(path.join(__dirname, 'data', 'provinces.json'), 'utf8');
31
  res.json(JSON.parse(data));
32
  } catch (error) {
33
  res.status(404).json({ error: 'Provinces not found' });
 
38
  app.get('/api/provinces/:provinceId/regencies', async (req, res) => {
39
  const { provinceId } = req.params;
40
  try {
41
+ const data = await fs.readFile(path.join(__dirname, 'data', provinceId, 'regencies.json'), 'utf8');
42
  res.json(JSON.parse(data));
43
  } catch (error) {
44
  res.status(404).json({ error: 'Regencies not found for this province' });
 
49
  app.get('/api/provinces/:provinceId/regencies/:regencyId/districts', async (req, res) => {
50
  const { provinceId, regencyId } = req.params;
51
  try {
52
+ const data = await fs.readFile(path.join(__dirname, 'data', provinceId, regencyId, 'district.json'), 'utf8');
53
  res.json(JSON.parse(data));
54
  } catch (error) {
55
  res.status(404).json({ error: 'Districts not found for this regency' });
 
60
  app.get('/api/provinces/:provinceId/regencies/:regencyId/districts/:districtId/villages', async (req, res) => {
61
  const { provinceId, regencyId, districtId } = req.params;
62
  try {
63
+ const data = await fs.readFile(path.join(__dirname, 'data', provinceId, regencyId, districtId, 'subdistrict.json'), 'utf8');
64
  res.json(JSON.parse(data));
65
  } catch (error) {
66
  res.status(404).json({ error: 'Villages not found for this district' });