Spaces:
Sleeping
Sleeping
deveix
commited on
Commit
·
9eec0ff
1
Parent(s):
27b275b
add json
Browse files- .DS_Store +0 -0
- app/.DS_Store +0 -0
- app/main.py +30 -7
- app/reciters.json +0 -0
- requirements.txt +1 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app/.DS_Store
ADDED
|
Binary file (10.2 kB). View file
|
|
|
app/main.py
CHANGED
|
@@ -25,6 +25,28 @@ import opensmile
|
|
| 25 |
import ffmpeg
|
| 26 |
import noisereduce as nr
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
default_sample_rate=22050
|
| 30 |
|
|
@@ -302,22 +324,23 @@ async def handle_cnn(file: UploadFile = File(...)):
|
|
| 302 |
|
| 303 |
# Make predictions
|
| 304 |
predictions = cnn_model.predict(X)
|
| 305 |
-
print('predictions', predictions)
|
| 306 |
|
| 307 |
# Convert predictions to label indexes
|
| 308 |
-
predicted_label_indexes = np.argmax(predictions
|
| 309 |
|
| 310 |
# Convert label indexes to actual label names
|
| 311 |
-
predicted_labels = cnn_label_encoder.inverse_transform(predicted_label_indexes)
|
| 312 |
|
| 313 |
print('decoded', predicted_labels)
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
| 317 |
# Clean up the temporary file
|
| 318 |
os.remove(temp_filename)
|
| 319 |
# Return a successful response with decoded predictions
|
| 320 |
-
return {"message": "File processed successfully", "sheikh":
|
| 321 |
except Exception as e:
|
| 322 |
print(e)
|
| 323 |
# Handle possible exceptions
|
|
|
|
| 25 |
import ffmpeg
|
| 26 |
import noisereduce as nr
|
| 27 |
|
| 28 |
+
import json
|
| 29 |
+
|
| 30 |
+
# Path to the JSON file
|
| 31 |
+
json_filepath = 'reciters.json'
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def load_json_data(filepath):
|
| 35 |
+
"""Load JSON data from a file."""
|
| 36 |
+
with open(filepath, 'r', encoding='utf-8') as file:
|
| 37 |
+
return json.load(file)
|
| 38 |
+
|
| 39 |
+
# Load the JSON data from file
|
| 40 |
+
json_reciters = load_json_data(json_filepath)
|
| 41 |
+
|
| 42 |
+
def find_reciter_by_name(name):
|
| 43 |
+
"""Search for a reciter by name in the loaded JSON data."""
|
| 44 |
+
for reciter in json_reciters['reciters']:
|
| 45 |
+
if reciter['name'] == name:
|
| 46 |
+
return reciter
|
| 47 |
+
return None # Return None if no match is found
|
| 48 |
+
|
| 49 |
+
|
| 50 |
|
| 51 |
default_sample_rate=22050
|
| 52 |
|
|
|
|
| 324 |
|
| 325 |
# Make predictions
|
| 326 |
predictions = cnn_model.predict(X)
|
| 327 |
+
print('predictions', np.argmax(predictions))
|
| 328 |
|
| 329 |
# Convert predictions to label indexes
|
| 330 |
+
predicted_label_indexes = np.argmax(predictions)
|
| 331 |
|
| 332 |
# Convert label indexes to actual label names
|
| 333 |
+
predicted_labels = cnn_label_encoder.inverse_transform([predicted_label_indexes])
|
| 334 |
|
| 335 |
print('decoded', predicted_labels)
|
| 336 |
+
reciter_name = predicted_labels[0]
|
| 337 |
+
# Find the reciter by name
|
| 338 |
+
reciter_object = find_reciter_by_name(reciter_name)
|
| 339 |
+
|
| 340 |
# Clean up the temporary file
|
| 341 |
os.remove(temp_filename)
|
| 342 |
# Return a successful response with decoded predictions
|
| 343 |
+
return {"message": "File processed successfully", "sheikh": reciter_object}
|
| 344 |
except Exception as e:
|
| 345 |
print(e)
|
| 346 |
# Handle possible exceptions
|
app/reciters.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
CHANGED
|
@@ -15,6 +15,7 @@ librosa
|
|
| 15 |
soundfile
|
| 16 |
opensmile
|
| 17 |
eyeD3
|
|
|
|
| 18 |
matplotlib
|
| 19 |
python-multipart
|
| 20 |
ffmpeg-python
|
|
|
|
| 15 |
soundfile
|
| 16 |
opensmile
|
| 17 |
eyeD3
|
| 18 |
+
json
|
| 19 |
matplotlib
|
| 20 |
python-multipart
|
| 21 |
ffmpeg-python
|