jhansi1 commited on
Commit
db3f254
1 Parent(s): 219c6cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,10 +1,23 @@
1
  from huggingface_hub import hf_hub_download
2
  from transformers import AutoModelForPreTraining, AutoTokenizer
 
3
 
4
- # Download model and tokenizer
5
  model_path = hf_hub_download("law-ai/InLegalBERT", filename="pytorch_model.bin")
6
  tokenizer_path = hf_hub_download("law-ai/InLegalBERT", filename="tokenizer_config.json")
7
 
8
- # Load locally downloaded model and tokenizer
9
- tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
10
- model = AutoModelForPreTraining.from_pretrained(model_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from huggingface_hub import hf_hub_download
2
  from transformers import AutoModelForPreTraining, AutoTokenizer
3
+ import os
4
 
5
+ # Download model and tokenizer files
6
  model_path = hf_hub_download("law-ai/InLegalBERT", filename="pytorch_model.bin")
7
  tokenizer_path = hf_hub_download("law-ai/InLegalBERT", filename="tokenizer_config.json")
8
 
9
+ # Define the path where the model and tokenizer will be loaded from
10
+ model_directory = "/tmp/InLegalBERT"
11
+
12
+ # Create the directory if it doesn't exist
13
+ os.makedirs(model_directory, exist_ok=True)
14
+
15
+ # Move the downloaded files to the appropriate directory
16
+ os.rename(model_path, os.path.join(model_directory, "pytorch_model.bin"))
17
+ os.rename(tokenizer_path, os.path.join(model_directory, "tokenizer_config.json"))
18
+
19
+ # Load the model and tokenizer from the local directory
20
+ tokenizer = AutoTokenizer.from_pretrained(model_directory)
21
+ model = AutoModelForPreTraining.from_pretrained(model_directory)
22
+
23
+ print("Model and tokenizer loaded successfully!")