Kamalaskar Disha Vinay (EXT) commited on
Commit ·
8d6129a
1
Parent(s): 4e6f78f
change requirements and model
Browse files- app.py +20 -6
- requirements.txt +1 -0
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")
|
|
@@ -100,15 +101,28 @@ class AVVideoModel(nn.Module):
|
|
| 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 |
-
#
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
model.eval()
|
| 109 |
-
print("✅ Model loaded
|
| 110 |
-
|
| 111 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|
|
|
|
| 101 |
return fused_logits, a_logits, t_logits, v_logits
|
| 102 |
|
| 103 |
# Load model
|
| 104 |
+
|
| 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="ApurvaKondekar/emotion_model", # CHANGE THIS
|
| 111 |
+
filename="model_weights.pth" # YOUR FILE NAME
|
| 112 |
+
)
|
| 113 |
+
model.load_state_dict(torch.load(model_path, map_location=DEVICE))
|
| 114 |
model.eval()
|
| 115 |
+
print("✅ Model loaded from Hugging Face")
|
| 116 |
+
except Exception as e:
|
| 117 |
+
print(f"❌ Failed to load model: {e}")
|
| 118 |
+
# Alternative: Create a dummy model for testing
|
| 119 |
+
# Load trained weights (you'll need to upload this)
|
| 120 |
+
if os.path.exists("model_weights.pth"):
|
| 121 |
+
model.load_state_dict(torch.load("model_weights.pth", map_location=DEVICE))
|
| 122 |
+
model.eval()
|
| 123 |
+
print("✅ Model loaded successfully")
|
| 124 |
+
else:
|
| 125 |
+
print("⚠️ No model weights found. Using untrained model for demo.")
|
| 126 |
|
| 127 |
def extract_video_frames(video_path, max_frames=8, resize=(224, 224)):
|
| 128 |
"""Extract frames from video file"""
|
requirements.txt
CHANGED
|
@@ -6,3 +6,4 @@ opencv-python-headless
|
|
| 6 |
numpy
|
| 7 |
soundfile
|
| 8 |
accelerate
|
|
|
|
|
|
| 6 |
numpy
|
| 7 |
soundfile
|
| 8 |
accelerate
|
| 9 |
+
huggingface_hub
|