Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,13 @@ import os
|
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
model_id = "TheBloke/Mistral-7B-Instruct-v0.1-GPTQ"
|
| 7 |
|
| 8 |
# Load Hugging Face token from environment variable
|
| 9 |
access_token = os.getenv("hf_mistral_token")
|
| 10 |
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True, token=access_token)
|
| 12 |
-
quant_config = BitsAndBytesConfig(load_in_4bit=True)
|
| 13 |
|
| 14 |
bnb_config = BitsAndBytesConfig(
|
| 15 |
load_in_4bit=True,
|
|
@@ -18,7 +17,7 @@ def load_model():
|
|
| 18 |
bnb_4bit_compute_dtype="float16"
|
| 19 |
)
|
| 20 |
|
| 21 |
-
|
| 22 |
model_id,
|
| 23 |
quantization_config=bnb_config,
|
| 24 |
device_map="auto"
|
|
@@ -27,6 +26,7 @@ def load_model():
|
|
| 27 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 28 |
return pipe
|
| 29 |
|
|
|
|
| 30 |
def main():
|
| 31 |
|
| 32 |
# st.set_page_config(page_title="ChatGPT Clone", page_icon="🤖")
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 4 |
|
| 5 |
+
def load_model():
|
| 6 |
+
model_id = "TheBloke/Mistral-7B-Instruct-v0.1-GPTQ" # 4-bit quantized model
|
| 7 |
|
| 8 |
# Load Hugging Face token from environment variable
|
| 9 |
access_token = os.getenv("hf_mistral_token")
|
| 10 |
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True, token=access_token)
|
|
|
|
| 12 |
|
| 13 |
bnb_config = BitsAndBytesConfig(
|
| 14 |
load_in_4bit=True,
|
|
|
|
| 17 |
bnb_4bit_compute_dtype="float16"
|
| 18 |
)
|
| 19 |
|
| 20 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 21 |
model_id,
|
| 22 |
quantization_config=bnb_config,
|
| 23 |
device_map="auto"
|
|
|
|
| 26 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 27 |
return pipe
|
| 28 |
|
| 29 |
+
|
| 30 |
def main():
|
| 31 |
|
| 32 |
# st.set_page_config(page_title="ChatGPT Clone", page_icon="🤖")
|