Update app.py
Browse files
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 |
-
#
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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!")
|