Spaces:
Running
Running
Commit
•
7a2502d
1
Parent(s):
81f2e59
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import gradio as gr
|
3 |
+
import requests
|
4 |
+
|
5 |
+
def upload_audio(audio_path):
|
6 |
+
try:
|
7 |
+
with open(audio_path, 'rb') as audio_file:
|
8 |
+
response = requests.post('http://sls-titan-6.csail.mit.edu:8080/upload/', files={'audio_file': audio_file})
|
9 |
+
if response.status_code == 200:
|
10 |
+
return response.json()["path"]
|
11 |
+
except:
|
12 |
+
return None
|
13 |
+
|
14 |
+
def predict(audio_path, question):
|
15 |
+
upload_statues = upload_audio(audio_path)
|
16 |
+
if upload_statues == None:
|
17 |
+
return 'Please upload an audio file.'
|
18 |
+
if question == '':
|
19 |
+
return 'Please ask a question.'
|
20 |
+
print(audio_path, question)
|
21 |
+
response = requests.put('http://sls-titan-6.csail.mit.edu:8080/items/0', json={
|
22 |
+
'audio_path': audio_path, 'question': question
|
23 |
+
})
|
24 |
+
answer = json.loads(response.content)
|
25 |
+
ans_str = answer['output']
|
26 |
+
return ans_str
|
27 |
+
|
28 |
+
if __name__ == '__main__':
|
29 |
+
link = "https://github.com/YuanGongND/ltu"
|
30 |
+
text = "[Github]"
|
31 |
+
paper_link = "https://arxiv.org/pdf/2305.10790.pdf"
|
32 |
+
paper_text = "[Paper]"
|
33 |
+
sample_audio_link = "https://drive.google.com/drive/folders/17yeBevX0LIS1ugt0DZDOoJolwxvncMja?usp=sharing"
|
34 |
+
sample_audio_text = "[sample audios from AudioSet evaluation set]"
|
35 |
+
demo = gr.Interface(fn=predict,
|
36 |
+
inputs=[gr.Audio(type="filepath"),
|
37 |
+
gr.Textbox(value='What can be inferred from the spoken text and sounds? Why?',
|
38 |
+
label='Edit the textbox to ask your own questions!')],
|
39 |
+
outputs=[gr.Textbox(label="LTU Output")],
|
40 |
+
cache_examples=True,
|
41 |
+
title="Demo of LTU-2 Beta",
|
42 |
+
description="LTU-2 an improved version of LTU. LTU-2 is stronger in spoken text understanding and music understanding. <br>" +
|
43 |
+
"LTU is authored by Yuan Gong, Alexander H. Liu, Hongyin Luo, Leonid Karlinsky, and James Glass (MIT & MIT-IBM Watson AI Lab). <br>" +
|
44 |
+
"**Please note that the model is under construction and may be buggy. It is trained with some new techniques that are not described in LTU paper. I.e., using method described in LTU paper cannot reproduce this model.**<br>" +
|
45 |
+
"Input should be wav file sampled at 16kHz. This demo trim input audio to 10 seconds."
|
46 |
+
"**Research Demo, No Commercial Use (Due to license of LLaMA).**")
|
47 |
+
demo.launch(debug=False, share=False)
|