Nick Starkov commited on
Commit
7ec4963
·
1 Parent(s): 45a2bd8
Files changed (2) hide show
  1. Dockerfile +12 -13
  2. app.py +5 -8
Dockerfile CHANGED
@@ -4,13 +4,16 @@ FROM python:3.10-slim
4
  # Set the working directory inside the container
5
  WORKDIR /app
6
 
7
- # Set Hugging Face cache directories to a writable location
8
- ENV HF_HOME=/app/.cache
9
- ENV HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface
 
10
 
11
  # Create cache directory and set permissions
12
- RUN mkdir -p /app/.cache/huggingface && \
13
- chmod -R 777 /app/.cache
 
 
14
 
15
  # Copy the requirements file to install dependencies
16
  COPY requirements.txt .
@@ -21,12 +24,8 @@ RUN pip install --no-cache-dir -r requirements.txt
21
  # Copy the application code
22
  COPY app.py .
23
 
24
- # Create a non-root user and switch to it
25
- RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
26
- USER appuser
27
-
28
- # Expose the port Flask will run on
29
- EXPOSE 8000
30
 
31
- # Command to run the Flask application
32
- CMD ["python", "app.py"]
 
4
  # Set the working directory inside the container
5
  WORKDIR /app
6
 
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ gcc \
10
+ && rm -rf /var/lib/apt/lists/*
11
 
12
  # Create cache directory and set permissions
13
+ RUN mkdir -p /app/cache && chmod -R 777 /app/cache
14
+
15
+ # Set environment variable for Hugging Face cache
16
+ ENV HF_HOME=/app/cache
17
 
18
  # Copy the requirements file to install dependencies
19
  COPY requirements.txt .
 
24
  # Copy the application code
25
  COPY app.py .
26
 
27
+ # Expose port 7860 (default for Hugging Face Spaces)
28
+ EXPOSE 7860
 
 
 
 
29
 
30
+ # Command to run the FastAPI app with uvicorn
31
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,15 +1,15 @@
1
- from flask import Flask, jsonify
2
  from datasets import load_dataset
3
  import random
4
  import json
5
 
6
- app = Flask(__name__)
7
 
8
  # Load the dataset from Hugging Face
9
  dataset = load_dataset("UCSC-Admire/idiom-SFT-dataset-561-2024-12-06_00-40-30", split="train")
10
 
11
- @app.route('/api/idioms', methods=['GET'])
12
- def get_idioms():
13
  # Select 50 random idioms from the dataset
14
  idioms = random.sample(list(dataset), 50)
15
  # Extract required fields
@@ -26,7 +26,4 @@ def get_idioms():
26
  "example": item.get("sentence", ""),
27
  "definition": compound_type
28
  })
29
- return jsonify(response)
30
-
31
- if __name__ == '__main__':
32
- app.run(host='0.0.0.0', port=8000)
 
1
+ from fastapi import FastAPI
2
  from datasets import load_dataset
3
  import random
4
  import json
5
 
6
+ app = FastAPI()
7
 
8
  # Load the dataset from Hugging Face
9
  dataset = load_dataset("UCSC-Admire/idiom-SFT-dataset-561-2024-12-06_00-40-30", split="train")
10
 
11
+ @app.get("/api/idioms")
12
+ async def get_idioms():
13
  # Select 50 random idioms from the dataset
14
  idioms = random.sample(list(dataset), 50)
15
  # Extract required fields
 
26
  "example": item.get("sentence", ""),
27
  "definition": compound_type
28
  })
29
+ return response