Spaces:
Sleeping
Sleeping
fix cache permission
Browse files- Dockerfile +3 -7
- app.py +5 -5
Dockerfile
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
-
# Use an official Python runtime as a parent image
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
-
# Set the working directory in the container
|
| 5 |
WORKDIR /code
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
|
| 10 |
-
# Install any needed packages specified in requirements.txt
|
| 11 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 12 |
|
| 13 |
-
# Copy the rest of the application's code to the working directory
|
| 14 |
COPY . /code/
|
| 15 |
|
| 16 |
-
# Expose the port the app runs on
|
| 17 |
EXPOSE 7860
|
| 18 |
|
| 19 |
-
# Define the command to run the application
|
| 20 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
+
ENV HF_HOME=/code/cache
|
| 6 |
+
RUN mkdir -p /code/cache && chmod -R 777 /code/cache
|
| 7 |
+
|
| 8 |
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
|
|
|
|
| 10 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
|
|
|
|
| 12 |
COPY . /code/
|
| 13 |
|
|
|
|
| 14 |
EXPOSE 7860
|
| 15 |
|
|
|
|
| 16 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -12,7 +12,7 @@ from pydantic import BaseModel
|
|
| 12 |
from PIL import Image
|
| 13 |
import torch
|
| 14 |
import torch.nn.functional as F
|
| 15 |
-
from transformers import
|
| 16 |
import tensorflow as tf
|
| 17 |
import numpy as np
|
| 18 |
from huggingface_hub import hf_hub_download
|
|
@@ -34,8 +34,8 @@ def load_models():
|
|
| 34 |
"""Load all models from Hugging Face Hub at startup."""
|
| 35 |
logging.info("Loading all models from the Hub...")
|
| 36 |
try:
|
| 37 |
-
tokenizer =
|
| 38 |
-
sentiment_model =
|
| 39 |
sentiment_model.to(device)
|
| 40 |
logging.info("Sentiment analysis model loaded successfully.")
|
| 41 |
except Exception as e:
|
|
@@ -75,7 +75,7 @@ async def predict_sentiment(request: SentimentRequest):
|
|
| 75 |
with torch.no_grad():
|
| 76 |
outputs = sentiment_model(**inputs)
|
| 77 |
probabilities = F.softmax(outputs.logits, dim=-1).squeeze()
|
| 78 |
-
labels = ['Bearish', 'Bullish'
|
| 79 |
prediction = labels[torch.argmax(probabilities).item()]
|
| 80 |
return {"prediction": prediction}
|
| 81 |
except Exception as e:
|
|
@@ -101,4 +101,4 @@ async def predict_catdog(file: UploadFile = File(...)):
|
|
| 101 |
return {"prediction": label}
|
| 102 |
except Exception as e:
|
| 103 |
logging.error(f"Cat/Dog prediction error: {e}")
|
| 104 |
-
raise HTTPException(status_code=500, detail="An error occurred during image classification.")
|
|
|
|
| 12 |
from PIL import Image
|
| 13 |
import torch
|
| 14 |
import torch.nn.functional as F
|
| 15 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 16 |
import tensorflow as tf
|
| 17 |
import numpy as np
|
| 18 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 34 |
"""Load all models from Hugging Face Hub at startup."""
|
| 35 |
logging.info("Loading all models from the Hub...")
|
| 36 |
try:
|
| 37 |
+
tokenizer = DistilBertTokenizer.from_pretrained("muhalwan/sental")
|
| 38 |
+
sentiment_model = DistilBertForSequenceClassification.from_pretrained("muhalwan/sental")
|
| 39 |
sentiment_model.to(device)
|
| 40 |
logging.info("Sentiment analysis model loaded successfully.")
|
| 41 |
except Exception as e:
|
|
|
|
| 75 |
with torch.no_grad():
|
| 76 |
outputs = sentiment_model(**inputs)
|
| 77 |
probabilities = F.softmax(outputs.logits, dim=-1).squeeze()
|
| 78 |
+
labels = ['Bearish', 'Bullish']
|
| 79 |
prediction = labels[torch.argmax(probabilities).item()]
|
| 80 |
return {"prediction": prediction}
|
| 81 |
except Exception as e:
|
|
|
|
| 101 |
return {"prediction": label}
|
| 102 |
except Exception as e:
|
| 103 |
logging.error(f"Cat/Dog prediction error: {e}")
|
| 104 |
+
raise HTTPException(status_code=500, detail="An error occurred during image classification.")
|