Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,12 @@ import gradio as gr
|
|
| 2 |
import librosa
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
-
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 6 |
from simple_salesforce import Salesforce
|
| 7 |
import os
|
| 8 |
from datetime import datetime
|
| 9 |
import logging
|
| 10 |
-
import
|
| 11 |
import webrtcvad
|
| 12 |
|
| 13 |
# Set up logging
|
|
@@ -101,7 +101,6 @@ def transcribe_audio(audio_file):
|
|
| 101 |
|
| 102 |
def analyze_symptoms(text):
|
| 103 |
"""Mock symptom-to-disease analysis (placeholder for symptom-2-disease-net)."""
|
| 104 |
-
# Since abhirajeshbhai/symptom-2-disease-net is not locally available, use rule-based analysis
|
| 105 |
text = text.lower()
|
| 106 |
feedback = []
|
| 107 |
if "cough" in text or "difficulty breathing" in text:
|
|
@@ -212,12 +211,14 @@ def test_with_sample_audio():
|
|
| 212 |
if not isinstance(dummy_audio, np.ndarray) or dummy_audio.ndim != 1:
|
| 213 |
logger.error(f"Invalid dummy_audio: type={type(dummy_audio)}, shape={dummy_audio.shape if hasattr(dummy_audio, 'shape') else 'N/A'}")
|
| 214 |
raise ValueError("Generated audio is not a 1D NumPy array")
|
|
|
|
|
|
|
| 215 |
logger.info(f"Dummy audio shape: {dummy_audio.shape}, type: {type(dummy_audio)}, dtype: {dummy_audio.dtype}")
|
| 216 |
sample_audio_path = "audio_samples/dummy_test.wav"
|
| 217 |
os.makedirs("audio_samples", exist_ok=True)
|
| 218 |
try:
|
| 219 |
-
#
|
| 220 |
-
|
| 221 |
logger.info(f"Generated dummy audio at: {sample_audio_path}")
|
| 222 |
# Verify file exists
|
| 223 |
if not os.path.exists(sample_audio_path):
|
|
|
|
| 2 |
import librosa
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 6 |
from simple_salesforce import Salesforce
|
| 7 |
import os
|
| 8 |
from datetime import datetime
|
| 9 |
import logging
|
| 10 |
+
from scipy.io import wavfile
|
| 11 |
import webrtcvad
|
| 12 |
|
| 13 |
# Set up logging
|
|
|
|
| 101 |
|
| 102 |
def analyze_symptoms(text):
|
| 103 |
"""Mock symptom-to-disease analysis (placeholder for symptom-2-disease-net)."""
|
|
|
|
| 104 |
text = text.lower()
|
| 105 |
feedback = []
|
| 106 |
if "cough" in text or "difficulty breathing" in text:
|
|
|
|
| 211 |
if not isinstance(dummy_audio, np.ndarray) or dummy_audio.ndim != 1:
|
| 212 |
logger.error(f"Invalid dummy_audio: type={type(dummy_audio)}, shape={dummy_audio.shape if hasattr(dummy_audio, 'shape') else 'N/A'}")
|
| 213 |
raise ValueError("Generated audio is not a 1D NumPy array")
|
| 214 |
+
# Normalize to int16 for scipy.io.wavfile
|
| 215 |
+
dummy_audio = (dummy_audio * 32767).astype(np.int16)
|
| 216 |
logger.info(f"Dummy audio shape: {dummy_audio.shape}, type: {type(dummy_audio)}, dtype: {dummy_audio.dtype}")
|
| 217 |
sample_audio_path = "audio_samples/dummy_test.wav"
|
| 218 |
os.makedirs("audio_samples", exist_ok=True)
|
| 219 |
try:
|
| 220 |
+
# Write audio using scipy.io.wavfile
|
| 221 |
+
wavfile.write(sample_audio_path, sr, dummy_audio)
|
| 222 |
logger.info(f"Generated dummy audio at: {sample_audio_path}")
|
| 223 |
# Verify file exists
|
| 224 |
if not os.path.exists(sample_audio_path):
|