Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +11 -4
- requirements.txt +2 -2
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import logging
|
|
|
2 |
from fastapi import FastAPI, HTTPException
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
4 |
from peft import PeftModel, PeftConfig
|
|
|
5 |
|
6 |
# Set up logging
|
7 |
logging.basicConfig(level=logging.INFO)
|
@@ -15,22 +17,27 @@ model = None
|
|
15 |
tokenizer = None
|
16 |
pipe = None
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
@app.on_event("startup")
|
19 |
async def load_model():
|
20 |
global model, tokenizer, pipe
|
21 |
|
22 |
try:
|
23 |
logger.info("Loading PEFT configuration...")
|
24 |
-
config = PeftConfig.from_pretrained("frankmorales2020/Mistral-7B-text-to-sql-flash-attention-2-dataeval")
|
25 |
|
26 |
logger.info("Loading base model...")
|
27 |
-
base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
28 |
|
29 |
logger.info("Loading PEFT model...")
|
30 |
-
model = PeftModel.from_pretrained(base_model, "frankmorales2020/Mistral-7B-text-to-sql-flash-attention-2-dataeval")
|
31 |
|
32 |
logger.info("Loading tokenizer...")
|
33 |
-
tokenizer =
|
34 |
|
35 |
logger.info("Creating pipeline...")
|
36 |
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
|
|
1 |
import logging
|
2 |
+
import os
|
3 |
from fastapi import FastAPI, HTTPException
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
5 |
from peft import PeftModel, PeftConfig
|
6 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
7 |
|
8 |
# Set up logging
|
9 |
logging.basicConfig(level=logging.INFO)
|
|
|
17 |
tokenizer = None
|
18 |
pipe = None
|
19 |
|
20 |
+
# Get the Hugging Face token from environment variable
|
21 |
+
hf_token = os.environ.get("HUGGINGFACE_TOKEN")
|
22 |
+
if not hf_token:
|
23 |
+
raise ValueError("HUGGINGFACE_TOKEN environment variable is not set")
|
24 |
+
|
25 |
@app.on_event("startup")
|
26 |
async def load_model():
|
27 |
global model, tokenizer, pipe
|
28 |
|
29 |
try:
|
30 |
logger.info("Loading PEFT configuration...")
|
31 |
+
config = PeftConfig.from_pretrained("frankmorales2020/Mistral-7B-text-to-sql-flash-attention-2-dataeval", token=hf_token)
|
32 |
|
33 |
logger.info("Loading base model...")
|
34 |
+
base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3", token=hf_token)
|
35 |
|
36 |
logger.info("Loading PEFT model...")
|
37 |
+
model = PeftModel.from_pretrained(base_model, "frankmorales2020/Mistral-7B-text-to-sql-flash-attention-2-dataeval", token=hf_token)
|
38 |
|
39 |
logger.info("Loading tokenizer...")
|
40 |
+
tokenizer = MistralTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3", token=hf_token)
|
41 |
|
42 |
logger.info("Creating pipeline...")
|
43 |
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
requirements.txt
CHANGED
@@ -2,9 +2,9 @@ fastapi==0.103.0
|
|
2 |
requests==2.27.*
|
3 |
uvicorn[standard]==0.17.*
|
4 |
torch>=1.13.0
|
5 |
-
transformers>=4.
|
6 |
numpy<2
|
7 |
-
peft>=0.
|
8 |
accelerate>=0.24.1,<0.25.0
|
9 |
huggingface_hub>=0.16.4,<0.18.0
|
10 |
tokenizers>=0.14.0,<0.15.0
|
|
|
2 |
requests==2.27.*
|
3 |
uvicorn[standard]==0.17.*
|
4 |
torch>=1.13.0
|
5 |
+
transformers>=4.36.0,<5.0.0
|
6 |
numpy<2
|
7 |
+
peft>=0.8.0
|
8 |
accelerate>=0.24.1,<0.25.0
|
9 |
huggingface_hub>=0.16.4,<0.18.0
|
10 |
tokenizers>=0.14.0,<0.15.0
|