Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,21 +6,23 @@ import gradio as gr
|
|
6 |
import spaces
|
7 |
import torch
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
|
|
|
|
9 |
|
10 |
MAX_MAX_NEW_TOKENS = 2048
|
11 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
12 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
13 |
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
|
26 |
@spaces.GPU
|
|
|
6 |
import spaces
|
7 |
import torch
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
9 |
+
from huggingface_hub import login
|
10 |
+
login(token="HUGGINGFACE_API_TOKEN")
|
11 |
|
12 |
MAX_MAX_NEW_TOKENS = 2048
|
13 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
14 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
15 |
|
16 |
|
17 |
+
if not torch.cuda.is_available():
|
18 |
+
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
19 |
|
20 |
|
21 |
+
if torch.cuda.is_available():
|
22 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
23 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True)
|
24 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
25 |
+
tokenizer.use_default_system_prompt = False
|
26 |
|
27 |
|
28 |
@spaces.GPU
|