Spaces:
Build error
Build error
Kartikeyssj2
commited on
Commit
•
7dde9f0
1
Parent(s):
c14d52f
changes
Browse files- WhatsApp Audio 2024-07-08 at 21.18.00_659e4840.waptt.opus +0 -0
- main.py +4 -0
- requirements.txt +2 -1
- test_api.py +41 -0
WhatsApp Audio 2024-07-08 at 21.18.00_659e4840.waptt.opus
ADDED
Binary file (66.8 kB). View file
|
|
main.py
CHANGED
@@ -8,6 +8,7 @@ from fastapi import FastAPI, File, UploadFile
|
|
8 |
import warnings
|
9 |
from starlette.formparsers import MultiPartParser
|
10 |
import io
|
|
|
11 |
|
12 |
|
13 |
MultiPartParser.max_file_size = 200 * 1024 * 1024
|
@@ -72,6 +73,9 @@ def apply_spell_check(item, word_list):
|
|
72 |
async def root():
|
73 |
return "Welcome to the pronunciation scoring API!"
|
74 |
|
|
|
|
|
|
|
75 |
@app.post('/pronunciation_scoring')
|
76 |
async def unscripted_root(audio_file: UploadFile):
|
77 |
print("Pronunciation Scoring")
|
|
|
8 |
import warnings
|
9 |
from starlette.formparsers import MultiPartParser
|
10 |
import io
|
11 |
+
import random
|
12 |
|
13 |
|
14 |
MultiPartParser.max_file_size = 200 * 1024 * 1024
|
|
|
73 |
async def root():
|
74 |
return "Welcome to the pronunciation scoring API!"
|
75 |
|
76 |
+
@app.post('/random_number_check')
|
77 |
+
async def rnc():
|
78 |
+
return random.randint(10)
|
79 |
@app.post('/pronunciation_scoring')
|
80 |
async def unscripted_root(audio_file: UploadFile):
|
81 |
print("Pronunciation Scoring")
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ librosa
|
|
4 |
torch
|
5 |
transformers
|
6 |
fastapi
|
7 |
-
starlette
|
|
|
|
4 |
torch
|
5 |
transformers
|
6 |
fastapi
|
7 |
+
starlette
|
8 |
+
random
|
test_api.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
|
4 |
+
# The URL of the pronunciation scoring API
|
5 |
+
url = "https://huggingface.co/spaces/Kartikeyssj2/pronunciation-scoring/pronunciation_scoring"
|
6 |
+
|
7 |
+
# Path to your audio file
|
8 |
+
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
|
9 |
+
|
10 |
+
# Check if the file exists
|
11 |
+
if not os.path.exists(audio_file_path):
|
12 |
+
print(f"Error: The file {audio_file_path} does not exist.")
|
13 |
+
exit(1)
|
14 |
+
|
15 |
+
# Prepare the files for the POST request
|
16 |
+
files = {
|
17 |
+
"audio_file": open(audio_file_path, 'rb')
|
18 |
+
}
|
19 |
+
|
20 |
+
try:
|
21 |
+
# Make the POST request
|
22 |
+
audio_file = open(audio_file_path , "rb")
|
23 |
+
print(audio_file)
|
24 |
+
response = requests.post(url, file = audio_file)
|
25 |
+
|
26 |
+
# Check if the request was successful
|
27 |
+
if response.status_code == 200:
|
28 |
+
# Parse the JSON response
|
29 |
+
result = response.json()
|
30 |
+
print("Transcription:", result["transcription"])
|
31 |
+
print("Pronunciation Score:", result["pronunciation_score"])
|
32 |
+
else:
|
33 |
+
print(f"Error: Received status code {response.status_code}")
|
34 |
+
print(response.text)
|
35 |
+
|
36 |
+
except requests.exceptions.RequestException as e:
|
37 |
+
print(f"An error occurred while making the request: {e}")
|
38 |
+
|
39 |
+
finally:
|
40 |
+
# Close the file
|
41 |
+
files['audio_file'].close()
|