koushikkumarkadari commited on
Commit
1a946a6
·
verified ·
1 Parent(s): 0f06b73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -3,9 +3,31 @@ import torch
3
  from transformers import AutoTokenizer, AlbertForSequenceClassification
4
  import numpy as np
5
  import os
 
6
 
7
- # Define paths to saved models
 
 
 
 
 
 
 
 
8
  save_dir = "./saved_models"
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  tasks = ["sentiment", "emotion", "hate_speech", "sarcasm"]
10
  model_paths = {task: f"{save_dir}/{task}" for task in tasks}
11
 
@@ -24,7 +46,7 @@ tokenizer = AutoTokenizer.from_pretrained("ai4bharat/indic-bert")
24
  models = {}
25
  for task in tasks:
26
  if not os.path.exists(model_paths[task]):
27
- raise FileNotFoundError(f"Model directory {model_paths[task]} not found. Ensure saved_models/{task} exists.")
28
  models[task] = AlbertForSequenceClassification.from_pretrained(model_paths[task])
29
 
30
  # Function to predict for a single task
 
3
  from transformers import AutoTokenizer, AlbertForSequenceClassification
4
  import numpy as np
5
  import os
6
+ import gdown
7
 
8
+ # Define Google Drive folder IDs for each model
9
+ model_drive_ids = {
10
+ "sentiment": "your_sentiment_folder_id", # Replace with actual folder ID
11
+ "emotion": "your_emotion_folder_id", # Replace with actual folder ID
12
+ "hate_speech": "your_hate_speech_folder_id", # Replace with actual folder ID
13
+ "sarcasm": "your_sarcasm_folder_id" # Replace with actual folder ID
14
+ }
15
+
16
+ # Define local directory to store downloaded models
17
  save_dir = "./saved_models"
18
+ os.makedirs(save_dir, exist_ok=True)
19
+
20
+ # Download models from Google Drive
21
+ for task, folder_id in model_drive_ids.items():
22
+ output_dir = os.path.join(save_dir, task)
23
+ if not os.path.exists(output_dir):
24
+ gdown.download_folder(
25
+ f"https://drive.google.com/drive/folders/1kEXKoJxxD5-0FO8WvtagzseSIC5q-rRY?usp=sharing/{folder_id}",
26
+ output=output_dir,
27
+ quiet=False
28
+ )
29
+
30
+ # Define model paths
31
  tasks = ["sentiment", "emotion", "hate_speech", "sarcasm"]
32
  model_paths = {task: f"{save_dir}/{task}" for task in tasks}
33
 
 
46
  models = {}
47
  for task in tasks:
48
  if not os.path.exists(model_paths[task]):
49
+ raise FileNotFoundError(f"Model directory {model_paths[task]} not found.")
50
  models[task] = AlbertForSequenceClassification.from_pretrained(model_paths[task])
51
 
52
  # Function to predict for a single task