Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -62,11 +62,22 @@ def extract_feature(audio_path):
|
|
| 62 |
|
| 63 |
# Full pipeline: emotion detection + GPT response
|
| 64 |
def predict_and_reply(audio_path):
|
|
|
|
|
|
|
|
|
|
| 65 |
feature = extract_feature(audio_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
with torch.no_grad():
|
| 67 |
output = model(feature)
|
| 68 |
pred = torch.argmax(output, dim=1).item()
|
| 69 |
emotion = emotions[pred]
|
|
|
|
| 70 |
|
| 71 |
prompt = f"The user sounds {emotion.lower()}. What would you like to say to them?"
|
| 72 |
|
|
|
|
| 62 |
|
| 63 |
# Full pipeline: emotion detection + GPT response
|
| 64 |
def predict_and_reply(audio_path):
|
| 65 |
+
model.eval()
|
| 66 |
+
|
| 67 |
+
# Load and preprocess audio
|
| 68 |
feature = extract_feature(audio_path)
|
| 69 |
+
|
| 70 |
+
# Move model and input to correct device
|
| 71 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 72 |
+
model.to(device)
|
| 73 |
+
feature = feature.to(device)
|
| 74 |
+
|
| 75 |
+
# Predict
|
| 76 |
with torch.no_grad():
|
| 77 |
output = model(feature)
|
| 78 |
pred = torch.argmax(output, dim=1).item()
|
| 79 |
emotion = emotions[pred]
|
| 80 |
+
|
| 81 |
|
| 82 |
prompt = f"The user sounds {emotion.lower()}. What would you like to say to them?"
|
| 83 |
|