ehcalabres commited on
Commit
2931768
1 Parent(s): 461ed82

Added request to EMOVoice model and prediction logging

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +23 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .streamlit/
app.py CHANGED
@@ -1,4 +1,7 @@
 
1
  import os
 
 
2
  import streamlit as st
3
 
4
  EXAMPLE_PATH = []
@@ -19,12 +22,32 @@ file = None
19
 
20
  if input_mode == 'Upload audio':
21
  file = st.sidebar.file_uploader("Choose a file", type=['mp3', 'mp4', 'wav', 'flac'])
 
22
  elif input_mode == 'Select example':
23
  example_selected = st.sidebar.selectbox('Choose an audio example', EXAMPLE_PATH)
24
  file = open('data/' + example_selected, 'rb')
 
25
 
26
  if file is not None:
27
  st.write('Audio added!')
28
  audio_bytes = file.read()
29
  st.audio(audio_bytes)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  file.close()
 
1
+ import json
2
  import os
3
+ import requests
4
+ import json
5
  import streamlit as st
6
 
7
  EXAMPLE_PATH = []
 
22
 
23
  if input_mode == 'Upload audio':
24
  file = st.sidebar.file_uploader("Choose a file", type=['mp3', 'mp4', 'wav', 'flac'])
25
+ file_size = file.size if file else None
26
  elif input_mode == 'Select example':
27
  example_selected = st.sidebar.selectbox('Choose an audio example', EXAMPLE_PATH)
28
  file = open('data/' + example_selected, 'rb')
29
+ file_size = os.stat('data/' + example_selected).st_size
30
 
31
  if file is not None:
32
  st.write('Audio added!')
33
  audio_bytes = file.read()
34
  st.audio(audio_bytes)
35
+
36
+
37
+ url = "https://api-inference.huggingface.co/models/ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition"
38
+
39
+ payload=file
40
+ headers = {
41
+ 'Content-Type': 'audio/mp3',
42
+ 'Authorization': 'Bearer ' + st.secrets['API_TOKEN']
43
+ }
44
+
45
+ response = requests.request("POST", url, headers=headers, data=audio_bytes)
46
+
47
+ response.request
48
+
49
+ decoded_response = json.loads(response.text)
50
+ st.write(decoded_response)
51
+
52
+
53
  file.close()