Empereur-Pirate commited on
Commit
b837945
·
verified ·
1 Parent(s): b7c9474

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -5
main.py CHANGED
@@ -7,18 +7,25 @@ from typing import Optional, Any
7
  import torch
8
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer, GenerationConfig
9
  import os
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  try:
12
- # Attempt to fetch the token from the environment variable set in Spaces
13
  HUGGINGFACE_TOKEN = os.environ['HF_ACCESS_TOKEN']
14
  except KeyError:
15
  print('The environment variable "HF_ACCESS_TOKEN" is not found. Please configure it correctly in your Space.')
16
  sys.exit(1)
17
 
18
- # Authentication
19
- from huggingface_hub import interpreter_login
20
- interpreter_login()
21
-
22
  # Packages and model loading
23
  import torch
24
  base_model_id = "152334H/miqu-1-70b-sf"
 
7
  import torch
8
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer, GenerationConfig
9
  import os
10
+ from huggingface_hub import login
11
+
12
+ # Check whether we are executing inside a Hugging Face Space
13
+ SPACE_NAME = os.getenv("SPACE_NAME", default=None)
14
+ if SPACE_NAME is not None:
15
+ print(f"Running inside {SPACE_NAME} Space.")
16
+ try:
17
+ # Try to auto-login using the Space's environment variables
18
+ login(automatically=True)
19
+ except Exception as e:
20
+ print(f"Failed to auto-login ({str(e)}). Manually check the HF_ACCESS_TOKEN environment variable.")
21
+ sys.exit(1)
22
 
23
  try:
 
24
  HUGGINGFACE_TOKEN = os.environ['HF_ACCESS_TOKEN']
25
  except KeyError:
26
  print('The environment variable "HF_ACCESS_TOKEN" is not found. Please configure it correctly in your Space.')
27
  sys.exit(1)
28
 
 
 
 
 
29
  # Packages and model loading
30
  import torch
31
  base_model_id = "152334H/miqu-1-70b-sf"