Subodh358 commited on
Commit
74792b5
1 Parent(s): 6cf611e

Upload 3 files

Browse files
Files changed (2) hide show
  1. Dockerfile +0 -30
  2. main.py +7 -3
Dockerfile CHANGED
@@ -11,33 +11,3 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
12
  COPY --chown=user . /app
13
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
14
-
15
-
16
- # FROM python:3.9
17
-
18
- # # Set environment variables
19
- # ENV MODEL_NAME="meta-llama/Meta-Llama-3-8B-Instruct"
20
- # ENV TRANSFORMERS_CACHE="/app/transformers_cache"
21
- # ENV LC_ALL=C.UTF-8
22
- # ENV LANG=C.UTF-8
23
-
24
- # # Install additional dependencies if needed
25
- # RUN pip install --no-cache-dir fastapi uvicorn
26
-
27
- # # Create the app directory and set permissions
28
- # RUN mkdir /app && chmod -R 777 /app
29
-
30
- # # Set the working directory
31
- # WORKDIR /app
32
-
33
- # # Copy your model and code to the container
34
- # COPY ./app.py /app
35
- # COPY ./Dockerfile /app
36
- # COPY ./requirements.txt /app
37
-
38
-
39
- # # Expose the port FastAPI will run on
40
- # EXPOSE 8000
41
-
42
- # # Run FastAPI server
43
- # CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
 
11
 
12
  COPY --chown=user . /app
13
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py CHANGED
@@ -1,12 +1,16 @@
1
  from fastapi import FastAPI, HTTPException
2
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
 
3
 
4
  app = FastAPI()
5
 
6
- # Load model and tokenizer
 
 
 
7
  model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
- model = AutoModelForCausalLM.from_pretrained(model_name)
10
  generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
11
 
12
  @app.get("/")
 
1
  from fastapi import FastAPI, HTTPException
2
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
+ import os
4
 
5
  app = FastAPI()
6
 
7
+ # Hugging Face authentication token
8
+ hf_token = os.getenv("HF_TOKEN")
9
+
10
+ # Load model and tokenizer with the authentication token
11
  model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
12
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
13
+ model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token)
14
  generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
15
 
16
  @app.get("/")