Spaces:
Sleeping
Sleeping
File size: 4,087 Bytes
b7a3e32 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
#!/usr/bin/env python3
"""
Test script for audio roleplay API
"""
import requests
import json
import base64
# API configuration
API_BASE_URL = "http://localhost:8000"
# API_BASE_URL = "https://abao77-run-code-api.hf.space"
def test_text_message():
"""Test sending text message only"""
print("Testing text message...")
scenario = {
"scenario_title": "Restaurant Order",
"scenario_description": "Order food at a restaurant",
"scenario_context": "You are at a restaurant and want to order food",
"your_role": "Customer",
"key_vocabulary": ["menu", "order", "bill", "table"]
}
data = {
"session_id": "test-session-123",
"scenario": json.dumps(scenario),
"text_message": "Hello, I'd like to see the menu please."
}
try:
response = requests.post(f"{API_BASE_URL}/api/ai/roleplay", data=data)
if response.ok:
result = response.json()
print("β
Text message test successful!")
print(f"Response: {result.get('response', 'No response')}")
else:
print(f"β Text message test failed: {response.status_code}")
print(f"Error: {response.text}")
except Exception as e:
print(f"β Text message test error: {e}")
def test_audio_message():
"""Test sending audio file"""
print("\nTesting audio message...")
scenario = {
"scenario_title": "Restaurant Order",
"scenario_description": "Order food at a restaurant",
"scenario_context": "You are at a restaurant and want to order food",
"your_role": "Customer",
"key_vocabulary": ["menu", "order", "bill", "table"]
}
# Create a dummy audio file (in real scenario, this would be actual audio)
dummy_audio_data = b"fake_audio_data_for_testing"
data = {
"session_id": "test-session-456",
"scenario": json.dumps(scenario)
}
files = {
"audio_file": ("test_audio.wav", dummy_audio_data, "audio/wav")
}
try:
response = requests.post(f"{API_BASE_URL}/api/ai/roleplay", data=data, files=files)
if response.ok:
result = response.json()
print("β
Audio message test successful!")
print(f"Response: {result.get('response', 'No response')}")
else:
print(f"β Audio message test failed: {response.status_code}")
print(f"Error: {response.text}")
except Exception as e:
print(f"β Audio message test error: {e}")
def test_combined_message():
"""Test sending both text and audio"""
print("\nTesting combined text + audio message...")
scenario = {
"scenario_title": "Restaurant Order",
"scenario_description": "Order food at a restaurant",
"scenario_context": "You are at a restaurant and want to order food",
"your_role": "Customer",
"key_vocabulary": ["menu", "order", "bill", "table"]
}
dummy_audio_data = b"fake_audio_data_for_testing"
data = {
"session_id": "test-session-789",
"scenario": json.dumps(scenario),
"text_message": "I have a question about the menu"
}
files = {
"audio_file": ("question.wav", dummy_audio_data, "audio/wav")
}
try:
response = requests.post(f"{API_BASE_URL}/api/ai/roleplay", data=data, files=files)
if response.ok:
result = response.json()
print("β
Combined message test successful!")
print(f"Response: {result.get('response', 'No response')}")
else:
print(f"β Combined message test failed: {response.status_code}")
print(f"Error: {response.text}")
except Exception as e:
print(f"β Combined message test error: {e}")
if __name__ == "__main__":
print("π§ͺ Testing Audio Roleplay API")
print("=" * 50)
test_text_message()
test_audio_message()
test_combined_message()
print("\n" + "=" * 50)
print("π Testing completed!")
|