Spaces:
Runtime error
Runtime error
fixed audio interface
Browse files
1.wav
ADDED
Binary file (317 kB). View file
|
|
app.py
CHANGED
@@ -1,80 +1,47 @@
|
|
1 |
# Welcome to Team Tonic's MultiMed
|
2 |
-
|
3 |
-
LANGUAGE_NAME_TO_CODE,
|
4 |
-
S2ST_TARGET_LANGUAGE_NAMES,
|
5 |
-
S2TT_TARGET_LANGUAGE_NAMES,
|
6 |
-
T2TT_TARGET_LANGUAGE_NAMES,
|
7 |
-
TEXT_SOURCE_LANGUAGE_NAMES,
|
8 |
-
LANG_TO_SPKR_ID,
|
9 |
-
)
|
10 |
from gradio_client import Client
|
11 |
import os
|
12 |
import numpy as np
|
13 |
import base64
|
14 |
-
import torch
|
15 |
-
import torchaudio
|
16 |
import gradio as gr
|
17 |
import requests
|
18 |
import json
|
19 |
import dotenv
|
20 |
-
from
|
21 |
-
import torchaudio
|
22 |
import PIL
|
23 |
dotenv.load_dotenv()
|
24 |
|
25 |
-
client = Client("
|
26 |
-
|
27 |
-
|
28 |
-
AUDIO_SAMPLE_RATE = 16000.0
|
29 |
-
MAX_INPUT_AUDIO_LENGTH = 60 # in seconds
|
30 |
-
DEFAULT_TARGET_LANGUAGE = "English"
|
31 |
|
32 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
33 |
|
34 |
|
35 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
36 |
|
37 |
-
|
38 |
-
# model = SeamlessM4TModel.from_pretrained("ylacombe/hf-seamless-m4t-large").to(device)
|
39 |
-
|
40 |
-
|
41 |
-
def process_speech(sound):
|
42 |
-
"""
|
43 |
-
processing sound using seamless_m4t
|
44 |
-
"""
|
45 |
-
# task_name = "T2TT"
|
46 |
-
result = client.predict(task_name="S2TT",
|
47 |
-
audio_source="microphone",
|
48 |
-
input_audio_mic=sound,
|
49 |
-
input_audio_file=None,
|
50 |
-
input_text=None,
|
51 |
-
source_language=None,
|
52 |
-
target_language="English")
|
53 |
-
print(result)
|
54 |
-
return result[1]
|
55 |
-
|
56 |
-
|
57 |
-
def process_speech_using_model(sound):
|
58 |
"""
|
59 |
processing sound using seamless_m4t
|
60 |
"""
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
|
79 |
|
80 |
def process_image(image) :
|
@@ -258,15 +225,7 @@ def process_and_query(text, image, audio):
|
|
258 |
text = process_image(image)
|
259 |
|
260 |
if audio is not None:
|
261 |
-
# audio = audio[0].numpy()
|
262 |
-
# audio = audio.astype(np.float32)
|
263 |
-
# audio = audio / np.max(np.abs(audio))
|
264 |
-
# audio = audio * 32768
|
265 |
-
# audio = audio.astype(np.int16)
|
266 |
-
# audio = audio.tobytes()
|
267 |
-
# audio = base64.b64encode(audio).decode('utf-8')
|
268 |
text = process_speech(audio)
|
269 |
-
print(text)
|
270 |
|
271 |
# Now, use the text (either provided by the user or obtained from OpenAI) to query Vectara
|
272 |
vectara_response_json = query_vectara(text)
|
|
|
1 |
# Welcome to Team Tonic's MultiMed
|
2 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from gradio_client import Client
|
4 |
import os
|
5 |
import numpy as np
|
6 |
import base64
|
|
|
|
|
7 |
import gradio as gr
|
8 |
import requests
|
9 |
import json
|
10 |
import dotenv
|
11 |
+
from scipy.io.wavfile import write
|
|
|
12 |
import PIL
|
13 |
dotenv.load_dotenv()
|
14 |
|
15 |
+
client = Client("facebook/seamless_m4t")
|
|
|
|
|
|
|
|
|
|
|
16 |
|
|
|
17 |
|
18 |
|
|
|
19 |
|
20 |
+
def process_speech(audio):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
"""
|
22 |
processing sound using seamless_m4t
|
23 |
"""
|
24 |
+
audio_name = f"{np.random.randint(0, 100)}.wav"
|
25 |
+
sr, data = audio
|
26 |
+
write(audio_name, sr, data.astype(np.int16))
|
27 |
+
|
28 |
+
out = client.predict(
|
29 |
+
"S2TT",
|
30 |
+
"file",
|
31 |
+
None,
|
32 |
+
audio_name,
|
33 |
+
"",
|
34 |
+
"French",# source language
|
35 |
+
"English",# target language
|
36 |
+
api_name="/run",
|
37 |
+
)
|
38 |
+
out = out[1] # get the text
|
39 |
+
try :
|
40 |
+
return f"{out}"
|
41 |
+
except Exception as e :
|
42 |
+
return f"{e}"
|
43 |
+
|
44 |
+
|
45 |
|
46 |
|
47 |
def process_image(image) :
|
|
|
225 |
text = process_image(image)
|
226 |
|
227 |
if audio is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
text = process_speech(audio)
|
|
|
229 |
|
230 |
# Now, use the text (either provided by the user or obtained from OpenAI) to query Vectara
|
231 |
vectara_response_json = query_vectara(text)
|
requirements.txt
CHANGED
@@ -5,3 +5,4 @@ torchaudio==2.0.2
|
|
5 |
sentencepiece
|
6 |
python-dotenv
|
7 |
Pillow
|
|
|
|
5 |
sentencepiece
|
6 |
python-dotenv
|
7 |
Pillow
|
8 |
+
scipy
|
test.py
CHANGED
@@ -5,57 +5,32 @@ import requests
|
|
5 |
import gradio as gr
|
6 |
import PIL
|
7 |
import numpy as np
|
8 |
-
|
|
|
9 |
dotenv.load_dotenv()
|
10 |
|
11 |
-
|
12 |
-
def process_image(
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
"
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
{
|
30 |
-
"role": "user",
|
31 |
-
"content": [
|
32 |
-
{
|
33 |
-
"type": "text",
|
34 |
-
"text": "What's in this image?"
|
35 |
-
},
|
36 |
-
{
|
37 |
-
"type": "image_url",
|
38 |
-
"image_url": {
|
39 |
-
"url": f"data:image/jpeg;base64,{base64_image}"
|
40 |
-
}
|
41 |
-
}
|
42 |
-
]
|
43 |
-
}
|
44 |
-
],
|
45 |
-
"max_tokens": 300
|
46 |
-
}
|
47 |
-
|
48 |
-
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
|
49 |
-
|
50 |
try :
|
51 |
-
out = response.json()
|
52 |
-
out = out["choices"][0]["message"]["content"]
|
53 |
-
print("out : ", out)
|
54 |
-
print("type(out) : ", type(out))
|
55 |
-
|
56 |
return f"{out}"
|
57 |
except Exception as e :
|
58 |
return f"{e}"
|
59 |
|
60 |
-
iface = gr.Interface(fn=process_image, inputs="
|
61 |
iface.launch()
|
|
|
5 |
import gradio as gr
|
6 |
import PIL
|
7 |
import numpy as np
|
8 |
+
from scipy.io.wavfile import write
|
9 |
+
import gradio_client as grc
|
10 |
dotenv.load_dotenv()
|
11 |
|
12 |
+
client = grc.Client("facebook/seamless_m4t")
|
13 |
+
def process_image(audio):
|
14 |
+
# audio_name = f"{np.random.randint(0, 100)}.jpg"
|
15 |
+
audio_name = f"{1}.wav"
|
16 |
+
sr, data = audio
|
17 |
+
write(audio_name, sr, data.astype(np.int16))
|
18 |
+
|
19 |
+
out = client.predict(
|
20 |
+
"S2TT",
|
21 |
+
"file",
|
22 |
+
None,
|
23 |
+
audio_name,
|
24 |
+
"",
|
25 |
+
"French",# source language
|
26 |
+
"English",# target language
|
27 |
+
api_name="/run",
|
28 |
+
)
|
29 |
+
out = out[1] # get the text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
try :
|
|
|
|
|
|
|
|
|
|
|
31 |
return f"{out}"
|
32 |
except Exception as e :
|
33 |
return f"{e}"
|
34 |
|
35 |
+
iface = gr.Interface(fn=process_image, inputs="audio", outputs="text")
|
36 |
iface.launch()
|