Hatman commited on
Commit
f24fccb
1 Parent(s): 8a7312c
Files changed (2) hide show
  1. app.py +5 -6
  2. requirements.txt +2 -1
app.py CHANGED
@@ -9,7 +9,8 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
9
  model_name = "Hemg/human-emotion-detection"
10
  feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
11
  model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
12
- model.to(device)
 
13
 
14
  def preprocess_audio(audio):
15
  waveform, sampling_rate = torchaudio.load(audio)
@@ -20,7 +21,7 @@ def preprocess_audio(audio):
20
  def inference(audio):
21
  example = preprocess_audio(audio)
22
  inputs = feature_extractor(example['speech'], sampling_rate=16000, return_tensors="pt", padding=True)
23
- inputs = inputs.to(device) # Move inputs to GPU
24
  with torch.no_grad():
25
  logits = model(**inputs).logits
26
  predicted_ids = torch.argmax(logits, dim=-1)
@@ -29,11 +30,9 @@ def inference(audio):
29
 
30
  iface = gr.Interface(fn=inference,
31
  inputs=gr.Audio(type="filepath"),
32
- outputs=[gr.Label(label="Predicted Sentiment"),
33
- gr.JSON(label="Logits"),
34
- gr.JSON(label="Predicted ID")],
35
  title="Audio Sentiment Analysis",
36
  description="Upload an audio file or record one to analyze sentiment.")
37
 
38
 
39
- iface.launch(share=True)
 
9
  model_name = "Hemg/human-emotion-detection"
10
  feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name)
11
  model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
12
+ print(device)
13
+
14
 
15
  def preprocess_audio(audio):
16
  waveform, sampling_rate = torchaudio.load(audio)
 
21
  def inference(audio):
22
  example = preprocess_audio(audio)
23
  inputs = feature_extractor(example['speech'], sampling_rate=16000, return_tensors="pt", padding=True)
24
+ inputs = inputs # Move inputs to GPU
25
  with torch.no_grad():
26
  logits = model(**inputs).logits
27
  predicted_ids = torch.argmax(logits, dim=-1)
 
30
 
31
  iface = gr.Interface(fn=inference,
32
  inputs=gr.Audio(type="filepath"),
33
+ outputs=[gr.Label(label="Predicted Sentiment")],
 
 
34
  title="Audio Sentiment Analysis",
35
  description="Upload an audio file or record one to analyze sentiment.")
36
 
37
 
38
+ iface.launch()
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  torch
2
  transformers
3
  accelerate
4
- torchaudio
 
 
1
  torch
2
  transformers
3
  accelerate
4
+ torchaudio
5
+ accelerate