barathm2001 commited on
Commit
5c19521
·
verified ·
1 Parent(s): 669915e

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +26 -0
  3. requirements.txt +8 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN useradd user
10
+
11
+ USER user
12
+
13
+ ENV HOME=/home/user \
14
+ PATH=/home/user/.local/bin:${PATH}
15
+
16
+ WORKDIR $HOME/app
17
+
18
+ COPY --chown=user . $HOME/app
19
+
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
3
+ from peft import PeftModel, PeftConfig
4
+
5
+ # Initialize FastAPI app
6
+ app = FastAPI()
7
+
8
+ # Load PEFT model configuration and base model
9
+ config = PeftConfig.from_pretrained("frankmorales2020/Mistral-7B-text-to-sql-flash-attention-2-dataeval")
10
+ base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
11
+ model = PeftModel.from_pretrained(base_model, "frankmorales2020/Mistral-7B-text-to-sql-flash-attention-2-dataeval")
12
+
13
+ # Load tokenizer
14
+ tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
15
+
16
+ # Create the pipeline
17
+ pipe = pipeline("text2sql", model=model, tokenizer=tokenizer)
18
+
19
+ @app.get("/")
20
+ def home():
21
+ return {"message": "Hello World"}
22
+
23
+ @app.get("/generate")
24
+ def generate(text: str):
25
+ output = pipe(text)
26
+ return {"output": output[0]['generated_text']}
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ sentencepiece==0.1.*
5
+ torch>=1.13.0
6
+ transformers==4.*
7
+ numpy<2
8
+ peft==0.11.1