spycoder commited on
Commit
15a6f16
1 Parent(s): 186636c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -43,24 +43,24 @@ The model was trained on Thai audio recordings with the following sentences: \n
43
 
44
 
45
 
46
- def predict(file_path):
47
  max_length = 100000
48
- # file_path = filepath(file_upload)
49
- # if (microphone is not None) and (file_upload is not None):
50
- # warn_output = (
51
- # "WARNING: You've uploaded an audio file and used the microphone. "
52
- # "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
53
- # )
54
-
55
- # elif (microphone is None) and (file_upload is None):
56
- # return "ERROR: You have to either use the microphone or upload an audio file"
57
- # if(microphone is not None):
58
- # file_path = filepath(microphone)
59
- # if(file_upload is not None):
60
- # file_path = filepath(microphone)
61
  model.eval()
62
  with torch.no_grad():
63
- wav_data, _ = sf.read(file_path.name)
64
  inputs = processor(wav_data, sampling_rate=16000, return_tensors="pt", padding=True)
65
 
66
  input_values = inputs.input_values.squeeze(0)
@@ -75,10 +75,13 @@ def predict(file_path):
75
  logits = logits.squeeze()
76
  predicted_class_id = torch.argmax(logits, dim=-1).item()
77
 
78
- return predicted_class_id
79
  gr.Interface(
80
  fn=predict,
81
- inputs=gr.inputs.Audio(type="file", label="Upload Audio File"),
 
 
 
82
  outputs="text",
83
  title=title,
84
  description=description,
 
43
 
44
 
45
 
46
+ def predict(file_upload,microphone):
47
  max_length = 100000
48
+ file_path =file_upload
49
+ if (microphone is not None) and (file_upload is not None):
50
+ warn_output = (
51
+ "WARNING: You've uploaded an audio file and used the microphone. "
52
+ "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
53
+ )
54
+
55
+ elif (microphone is None) and (file_upload is None):
56
+ return "ERROR: You have to either use the microphone or upload an audio file"
57
+ if(microphone is not None):
58
+ file_path = microphone
59
+ if(file_upload is not None):
60
+ file_path = file_upload
61
  model.eval()
62
  with torch.no_grad():
63
+ wav_data, _ = sf.read(file_path)
64
  inputs = processor(wav_data, sampling_rate=16000, return_tensors="pt", padding=True)
65
 
66
  input_values = inputs.input_values.squeeze(0)
 
75
  logits = logits.squeeze()
76
  predicted_class_id = torch.argmax(logits, dim=-1).item()
77
 
78
+ return "You probably have SP" if predicted_class_id == 1 else "You probably don't have SP"
79
  gr.Interface(
80
  fn=predict,
81
+ inputs=[
82
+ gr.inputs.Audio(source="upload", type="filepath", optional=True),
83
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True),
84
+ ],
85
  outputs="text",
86
  title=title,
87
  description=description,