Spaces:
Sleeping
Sleeping
Update app.py
Browse filesUpdate ASR Module
app.py
CHANGED
@@ -4,6 +4,7 @@ from huggingface_hub import InferenceClient
|
|
4 |
import os
|
5 |
import requests
|
6 |
import scipy.io.wavfile
|
|
|
7 |
|
8 |
client = InferenceClient(
|
9 |
"meta-llama/Meta-Llama-3-8B-Instruct",
|
@@ -56,23 +57,22 @@ def process_audio(audio_data):
|
|
56 |
else:
|
57 |
return "Invalid audio data format"
|
58 |
|
59 |
-
# Define the local file path to save the WAV file
|
60 |
-
local_wav_file = "converted_audio.wav"
|
61 |
|
62 |
-
#
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v2"
|
66 |
headers = {"Authorization": f"Bearer {os.getenv('hf_token')}"}
|
67 |
|
68 |
-
def query(
|
69 |
-
|
70 |
-
file_data = f.read()
|
71 |
-
response = requests.post(API_URL, headers=headers, data=file_data)
|
72 |
return response.json()
|
73 |
|
74 |
# Call the API to process the audio
|
75 |
-
output = query(
|
76 |
|
77 |
print(output)
|
78 |
|
|
|
4 |
import os
|
5 |
import requests
|
6 |
import scipy.io.wavfile
|
7 |
+
import io
|
8 |
|
9 |
client = InferenceClient(
|
10 |
"meta-llama/Meta-Llama-3-8B-Instruct",
|
|
|
57 |
else:
|
58 |
return "Invalid audio data format"
|
59 |
|
|
|
|
|
60 |
|
61 |
+
# Convert the audio data to WAV format in memory
|
62 |
+
buf = io.BytesIO()
|
63 |
+
scipy.io.wavfile.write(buf, sample_rate, data)
|
64 |
+
wav_bytes = buf.getvalue()
|
65 |
+
buf.close()
|
66 |
|
67 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v2"
|
68 |
headers = {"Authorization": f"Bearer {os.getenv('hf_token')}"}
|
69 |
|
70 |
+
def query(wav_data):
|
71 |
+
response = requests.post(API_URL, headers=headers, data=wav_data)
|
|
|
|
|
72 |
return response.json()
|
73 |
|
74 |
# Call the API to process the audio
|
75 |
+
output = query(wav_bytes)
|
76 |
|
77 |
print(output)
|
78 |
|