Spaces:
Build error
Build error
import requests | |
import os | |
# The URL of the pronunciation scoring API | |
url = "https://huggingface.co/spaces/Kartikeyssj2/pronunciation-scoring/pronunciation_scoring" | |
# Path to your audio file | |
audio_file_path = "D:\Freelancing\AI Feature Scoring\deployed endpoints\Pronunciation\Pronunciation_Scoring\pronunciation-scoring\WhatsApp Audio 2024-07-08 at 21.18.00_659e4840.waptt.opus" # Replace with the actual path to your audio file | |
# Check if the file exists | |
if not os.path.exists(audio_file_path): | |
print(f"Error: The file {audio_file_path} does not exist.") | |
exit(1) | |
# Prepare the files for the POST request | |
files = { | |
"audio_file": open(audio_file_path, 'rb') | |
} | |
try: | |
# Make the POST request | |
audio_file = open(audio_file_path , "rb") | |
print(audio_file) | |
response = requests.post(url, file = audio_file) | |
# Check if the request was successful | |
if response.status_code == 200: | |
# Parse the JSON response | |
result = response.json() | |
print("Transcription:", result["transcription"]) | |
print("Pronunciation Score:", result["pronunciation_score"]) | |
else: | |
print(f"Error: Received status code {response.status_code}") | |
print(response.text) | |
except requests.exceptions.RequestException as e: | |
print(f"An error occurred while making the request: {e}") | |
finally: | |
# Close the file | |
files['audio_file'].close() |