Spaces:
Sleeping
Sleeping
harshj0506
commited on
Commit
•
fd4fd19
1
Parent(s):
15b35e9
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,33 @@ from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassific
|
|
3 |
import torch
|
4 |
import torch.nn.functional as F
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Load the fine-tuned model and tokenizer
|
7 |
-
model_path = "
|
8 |
-
tokenizer_path = "
|
9 |
|
10 |
@st.cache_resource
|
11 |
def load_model():
|
|
|
3 |
import torch
|
4 |
import torch.nn.functional as F
|
5 |
|
6 |
+
import zipfile
|
7 |
+
import shutil
|
8 |
+
import os
|
9 |
+
|
10 |
+
def unzip_and_save(zip_file_path, extraction_path):
|
11 |
+
# Create the extraction directory if it doesn't exist
|
12 |
+
os.makedirs(extraction_path, exist_ok=True)
|
13 |
+
|
14 |
+
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
15 |
+
folder_name = os.path.basename(zip_file_path).split('.')[0]
|
16 |
+
zip_ref.extractall(extraction_path)
|
17 |
+
source_path = os.path.join(extraction_path, folder_name)
|
18 |
+
destination_path = os.path.join(extraction_path, folder_name)
|
19 |
+
if os.path.exists(destination_path):
|
20 |
+
print(f"Error: Destination path '{destination_path}' already exists")
|
21 |
+
else:
|
22 |
+
shutil.move(source_path, destination_path)
|
23 |
+
|
24 |
+
# Example usage:
|
25 |
+
zip_file_path = 'finetuned_bert_sentiment_harsh.zip' # Path to your ZIP file
|
26 |
+
extraction_path = 'bert_model_sentiment_v1' # Destination folder for extraction
|
27 |
+
|
28 |
+
unzip_and_save(zip_file_path, extraction_path)
|
29 |
+
|
30 |
# Load the fine-tuned model and tokenizer
|
31 |
+
model_path = "bert_model_sentiment_v1/finetuned_bert_sentiment_harsh"
|
32 |
+
tokenizer_path = "bert_model_sentiment_v1/finetuned_bert_sentiment_harsh"
|
33 |
|
34 |
@st.cache_resource
|
35 |
def load_model():
|