darwincb commited on
Commit
d8f1804
Β·
1 Parent(s): d4e6341

πŸ”§ Fix tokenizer compatibility + add fallback model for HF Spaces

Browse files
Files changed (2) hide show
  1. app.py +23 -8
  2. requirements.txt +10 -10
app.py CHANGED
@@ -16,14 +16,29 @@ import re
16
  # Initialize model
17
  print("πŸš€ Loading Jan v1 model...")
18
  model_name = "janhq/Jan-v1-4B"
19
- tokenizer = AutoTokenizer.from_pretrained(model_name)
20
- model = AutoModelForCausalLM.from_pretrained(
21
- model_name,
22
- torch_dtype=torch.bfloat16,
23
- device_map="auto",
24
- load_in_8bit=True
25
- )
26
- print("βœ… Jan v1 loaded successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  class SimpleWebSearch:
29
  def __init__(self):
 
16
  # Initialize model
17
  print("πŸš€ Loading Jan v1 model...")
18
  model_name = "janhq/Jan-v1-4B"
19
+
20
+ try:
21
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
22
+ model = AutoModelForCausalLM.from_pretrained(
23
+ model_name,
24
+ torch_dtype=torch.bfloat16,
25
+ device_map="auto",
26
+ load_in_8bit=True,
27
+ trust_remote_code=True
28
+ )
29
+ print("βœ… Jan v1 loaded successfully!")
30
+ except Exception as e:
31
+ print(f"❌ Error loading Jan v1: {e}")
32
+ print("πŸ”„ Falling back to basic model...")
33
+ # Fallback to a simpler model that works on HF Spaces
34
+ model_name = "microsoft/DialoGPT-medium"
35
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
36
+ model = AutoModelForCausalLM.from_pretrained(
37
+ model_name,
38
+ torch_dtype=torch.float16,
39
+ device_map="auto"
40
+ )
41
+ print("βœ… Fallback model loaded!")
42
 
43
  class SimpleWebSearch:
44
  def __init__(self):
requirements.txt CHANGED
@@ -1,11 +1,11 @@
1
  # Jan v1 Research Assistant - Complete requirements
2
- transformers==4.36.2
3
- torch==2.1.2
4
- gradio==4.19.2
5
- accelerate==0.25.0
6
- bitsandbytes==0.42.0
7
- sentencepiece==0.1.99
8
- beautifulsoup4==4.12.3
9
- requests==2.31.0
10
- lxml==5.1.0
11
- validators==0.22.0
 
1
  # Jan v1 Research Assistant - Complete requirements
2
+ transformers>=4.40.0
3
+ torch>=2.0.0
4
+ gradio>=4.19.0
5
+ accelerate>=0.25.0
6
+ bitsandbytes>=0.42.0
7
+ sentencepiece>=0.1.99
8
+ beautifulsoup4>=4.12.0
9
+ requests>=2.31.0
10
+ lxml>=5.1.0
11
+ validators>=0.22.0