ApurvaKondekar commited on
Commit
41321d9
·
verified ·
1 Parent(s): 4e6f78f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -9,6 +9,7 @@ from transformers import Wav2Vec2Processor, Wav2Vec2Model, AutoTokenizer, AutoMo
9
  from torchvision import models
10
  import tempfile
11
  import os
 
12
 
13
  # Configuration
14
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -99,16 +100,23 @@ class AVVideoModel(nn.Module):
99
 
100
  return fused_logits, a_logits, t_logits, v_logits
101
 
 
102
  # Load model
103
  model = AVVideoModel(num_classes=len(LABELS)).to(DEVICE)
104
 
105
- # Load trained weights (you'll need to upload this)
106
- if os.path.exists("model_weights.pth"):
107
- model.load_state_dict(torch.load("model_weights.pth", map_location=DEVICE))
 
 
 
 
 
108
  model.eval()
109
- print("✅ Model loaded successfully")
110
- else:
111
- print("⚠️ No model weights found. Using untrained model for demo.")
 
112
 
113
  def extract_video_frames(video_path, max_frames=8, resize=(224, 224)):
114
  """Extract frames from video file"""
 
9
  from torchvision import models
10
  import tempfile
11
  import os
12
+ from huggingface_hub import hf_hub_download
13
 
14
  # Configuration
15
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
100
 
101
  return fused_logits, a_logits, t_logits, v_logits
102
 
103
+ # Load model
104
  # Load model
105
  model = AVVideoModel(num_classes=len(LABELS)).to(DEVICE)
106
 
107
+ # Download model from Hugging Face Model Hub
108
+ try:
109
+ model_path = hf_hub_download(
110
+ repo_id="your-username/emotion-model", # CHANGE THIS
111
+ filename="model_weights.pth" # YOUR FILE NAME
112
+ )
113
+
114
+ model.load_state_dict(torch.load(model_path, map_location=DEVICE))
115
  model.eval()
116
+ print("✅ Model loaded from Hugging Face")
117
+
118
+ except Exception as e:
119
+ print(f"❌ Failed to load model: {e}")
120
 
121
  def extract_video_frames(video_path, max_frames=8, resize=(224, 224)):
122
  """Extract frames from video file"""