saronium commited on
Commit
c0f1a73
·
verified ·
1 Parent(s): 8b10513

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -4,10 +4,21 @@ import numpy as np
4
  from torchvision import models
5
  from scipy.ndimage import zoom
6
  import gradio as gr
 
 
7
 
8
  # Assuming you already have the 'ann_model' trained and 'pca' instance from the previous code
9
  language_mapping = {'malayalam': 0, 'english': 1, 'tamil': 2,'hindi':3,'kannada':4,'telugu':5}
10
 
 
 
 
 
 
 
 
 
 
11
  # Function to load and preprocess a single audio file
12
  def preprocess_single_audio_vgg16(audio_file, vgg16_model, pca_instance):
13
  # Your existing preprocessing code goes here
@@ -44,7 +55,7 @@ def preprocess_single_audio_vgg16(audio_file, vgg16_model, pca_instance):
44
 
45
  def predict_language(audio_file_path):
46
  # Load VGG16 model
47
- vgg16 = models.vgg16(pretrained=True).features
48
 
49
  # Preprocess the single audio file using VGG16 for feature extraction
50
  preprocessed_features = preprocess_single_audio_vgg16(audio_file_path, vgg16, pca)
 
4
  from torchvision import models
5
  from scipy.ndimage import zoom
6
  import gradio as gr
7
+ import pickle
8
+
9
 
10
  # Assuming you already have the 'ann_model' trained and 'pca' instance from the previous code
11
  language_mapping = {'malayalam': 0, 'english': 1, 'tamil': 2,'hindi':3,'kannada':4,'telugu':5}
12
 
13
+
14
+ # Load the trained model
15
+ with open('ann_model.pth', 'rb') as f:
16
+ ann_model = torch.load(f)
17
+
18
+ # Load the PCA instance
19
+ with open('pca.pkl', 'rb') as f:
20
+ pca = pickle.load(f)
21
+ vgg16 = models.vgg16(pretrained=True).features
22
  # Function to load and preprocess a single audio file
23
  def preprocess_single_audio_vgg16(audio_file, vgg16_model, pca_instance):
24
  # Your existing preprocessing code goes here
 
55
 
56
  def predict_language(audio_file_path):
57
  # Load VGG16 model
58
+
59
 
60
  # Preprocess the single audio file using VGG16 for feature extraction
61
  preprocessed_features = preprocess_single_audio_vgg16(audio_file_path, vgg16, pca)