Spaces:
Sleeping
Sleeping
Nick Starkov commited on
Commit ·
7ec4963
1
Parent(s): 45a2bd8
Changes
Browse files- Dockerfile +12 -13
- 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 |
-
#
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
# Create cache directory and set permissions
|
| 12 |
-
RUN mkdir -p /app/
|
| 13 |
-
|
|
|
|
|
|
|
| 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 |
-
#
|
| 25 |
-
|
| 26 |
-
USER appuser
|
| 27 |
-
|
| 28 |
-
# Expose the port Flask will run on
|
| 29 |
-
EXPOSE 8000
|
| 30 |
|
| 31 |
-
# Command to run the
|
| 32 |
-
CMD ["
|
|
|
|
| 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
|
| 2 |
from datasets import load_dataset
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
|
| 6 |
-
app =
|
| 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.
|
| 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
|
| 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
|
|
|
|
|
|
|
|
|