ezequiellopez commited on
Commit
8593270
·
1 Parent(s): 2c5907a

debugging setup

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -2
  2. app/main.py +4 -4
  3. requirements.txt +1 -2
Dockerfile CHANGED
@@ -7,16 +7,21 @@ ENV PYTHONDONTWRITEBYTECODE 1
7
  ENV PYTHONUNBUFFERED 1
8
  ENV HF_HOME /app/cache
9
 
 
 
 
10
  # Set the working directory in the container
11
  WORKDIR /app
12
 
13
  # Upgrade pip to the latest version and install Python dependencies
14
  COPY requirements.txt .
 
 
15
  RUN pip install --upgrade pip && pip install -r requirements.txt
16
 
17
  # Copy the FastAPI application code and other necessary files into the container
18
- COPY ./app .
19
- COPY .env .
20
 
21
  # Expose port 7860 for the application
22
  EXPOSE 7860
 
7
  ENV PYTHONUNBUFFERED 1
8
  ENV HF_HOME /app/cache
9
 
10
+ RUN useradd -m -u 1000 user
11
+ USER user
12
+
13
  # Set the working directory in the container
14
  WORKDIR /app
15
 
16
  # Upgrade pip to the latest version and install Python dependencies
17
  COPY requirements.txt .
18
+
19
+ RUN chown -R user:user /app
20
  RUN pip install --upgrade pip && pip install -r requirements.txt
21
 
22
  # Copy the FastAPI application code and other necessary files into the container
23
+ COPY --chown=user:user ./app .
24
+ COPY --chown=user:user .env .
25
 
26
  # Expose port 7860 for the application
27
  EXPOSE 7860
app/main.py CHANGED
@@ -2,7 +2,7 @@
2
  from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  from typing import List
5
- import redis
6
  from transformers import BartForSequenceClassification, BartTokenizer, AutoTokenizer, AutoConfig, pipeline
7
  from dotenv import load_dotenv
8
  import os
@@ -21,7 +21,7 @@ print("FastAPI port:", fastapi_port)
21
 
22
  # Initialize FastAPI app and Redis client
23
  app = FastAPI()
24
- redis_client = redis.Redis(host='redis', port=6379)
25
 
26
  # Load BART model and tokenizer
27
  #model = BartForSequenceClassification.from_pretrained("facebook/bart-large-mnli")
@@ -78,13 +78,13 @@ async def rerank_items(items: List[Item]) -> RerankedItems:
78
  labels = classify_item(item.text)
79
 
80
  # Save the item with labels in Redis
81
- redis_client.hset(item.id, mapping={"title": item.title, "text": item.text, "labels": ",".join(labels)})
82
 
83
  # Add the item id to the reranked list
84
  reranked_ids.append(item.id)
85
 
86
  # Sort the items based on model confidence
87
- reranked_ids.sort(key=lambda x: redis_client.zscore("classified_items", x), reverse=True)
88
 
89
  # Return the reranked items
90
  return {"ranked_ids": reranked_ids, "new_items": []} # Ignore "new_items" for now
 
2
  from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  from typing import List
5
+ #import redis
6
  from transformers import BartForSequenceClassification, BartTokenizer, AutoTokenizer, AutoConfig, pipeline
7
  from dotenv import load_dotenv
8
  import os
 
21
 
22
  # Initialize FastAPI app and Redis client
23
  app = FastAPI()
24
+ #redis_client = redis.Redis(host='redis', port=6379)
25
 
26
  # Load BART model and tokenizer
27
  #model = BartForSequenceClassification.from_pretrained("facebook/bart-large-mnli")
 
78
  labels = classify_item(item.text)
79
 
80
  # Save the item with labels in Redis
81
+ #redis_client.hset(item.id, mapping={"title": item.title, "text": item.text, "labels": ",".join(labels)})
82
 
83
  # Add the item id to the reranked list
84
  reranked_ids.append(item.id)
85
 
86
  # Sort the items based on model confidence
87
+ #reranked_ids.sort(key=lambda x: redis_client.zscore("classified_items", x), reverse=True)
88
 
89
  # Return the reranked items
90
  return {"ranked_ids": reranked_ids, "new_items": []} # Ignore "new_items" for now
requirements.txt CHANGED
@@ -5,5 +5,4 @@ python-dotenv
5
  dotenv-cli
6
  pandas
7
  uvicorn
8
- pydantic
9
- redis# remove for prototype
 
5
  dotenv-cli
6
  pandas
7
  uvicorn
8
+ pydantic