akhil2808 commited on
Commit
f1b9210
·
verified ·
1 Parent(s): f3be5b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
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
- #if not torch.cuda.is_available():
16
- # DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
17
 
18
 
19
- #if torch.cuda.is_available():
20
- # model_id = "mistralai/Mistral-7B-Instruct-v0.2"
21
- # model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True)
22
- # tokenizer = AutoTokenizer.from_pretrained(model_id)
23
- # tokenizer.use_default_system_prompt = False
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