Spaces:
Sleeping
Sleeping
SammyGasana
commited on
Commit
·
fabe773
1
Parent(s):
0fd0cfd
test sentiment analysis
Browse files- .huggingface.yml +2 -0
- __pycache__/audio_predictions.cpython-39.pyc +0 -0
- audio_predictions.py +7 -6
- evaluation.py +1 -1
- main.py +3 -0
.huggingface.yml
CHANGED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit:
|
2 |
+
app: main.py
|
__pycache__/audio_predictions.cpython-39.pyc
CHANGED
Binary files a/__pycache__/audio_predictions.cpython-39.pyc and b/__pycache__/audio_predictions.cpython-39.pyc differ
|
|
audio_predictions.py
CHANGED
@@ -25,21 +25,21 @@ class AudioTranslation:
|
|
25 |
converted_file_path = self.convert_to_mp3(file_path)
|
26 |
with open(converted_file_path, 'rb') as file:
|
27 |
files = {'file': (file_path, file, 'audio/mpeg')}
|
|
|
28 |
try:
|
29 |
response = requests.post(url, files=files)
|
30 |
response.raise_for_status()
|
31 |
transcription = response.json()
|
32 |
-
|
33 |
# Remove punctuation
|
34 |
translator = str.maketrans('', '', string.punctuation)
|
35 |
cleaned_text = transcription['text'].translate(translator)
|
|
|
36 |
print(cleaned_text)
|
37 |
return cleaned_text
|
38 |
except requests.exceptions.HTTPError as err:
|
39 |
print(f"HTTP error occurred: {err}")
|
40 |
except Exception as err:
|
41 |
print(f"An error occurred: {err}")
|
42 |
-
|
43 |
return None
|
44 |
|
45 |
def get_translation(self, src, tgt, text):
|
@@ -72,6 +72,7 @@ class AudioTranslation:
|
|
72 |
try:
|
73 |
response = requests.post(url, headers=headers, data=json.dumps(data))
|
74 |
response.raise_for_status()
|
|
|
75 |
return response.json()
|
76 |
except requests.exceptions.HTTPError as err:
|
77 |
print(f"HTTP error occurred: {err}")
|
@@ -96,10 +97,10 @@ class AudioTranslation:
|
|
96 |
return None
|
97 |
|
98 |
# Example usage
|
99 |
-
audio_translator = AudioTranslation()
|
100 |
-
transcription = audio_translator.transcribe_audio("voice_test_1.mp3")
|
101 |
-
translation_result = audio_translator.translate_sentence("rw", "en","MULTI-rw-en","", transcription)
|
102 |
-
print(translation_result)
|
103 |
'''
|
104 |
alternative models:
|
105 |
https://huggingface.co/facebook/nllb-200-3.3B
|
|
|
25 |
converted_file_path = self.convert_to_mp3(file_path)
|
26 |
with open(converted_file_path, 'rb') as file:
|
27 |
files = {'file': (file_path, file, 'audio/mpeg')}
|
28 |
+
print('transcribing audio')
|
29 |
try:
|
30 |
response = requests.post(url, files=files)
|
31 |
response.raise_for_status()
|
32 |
transcription = response.json()
|
|
|
33 |
# Remove punctuation
|
34 |
translator = str.maketrans('', '', string.punctuation)
|
35 |
cleaned_text = transcription['text'].translate(translator)
|
36 |
+
print('cleaned text')
|
37 |
print(cleaned_text)
|
38 |
return cleaned_text
|
39 |
except requests.exceptions.HTTPError as err:
|
40 |
print(f"HTTP error occurred: {err}")
|
41 |
except Exception as err:
|
42 |
print(f"An error occurred: {err}")
|
|
|
43 |
return None
|
44 |
|
45 |
def get_translation(self, src, tgt, text):
|
|
|
72 |
try:
|
73 |
response = requests.post(url, headers=headers, data=json.dumps(data))
|
74 |
response.raise_for_status()
|
75 |
+
print('translation sentence')
|
76 |
return response.json()
|
77 |
except requests.exceptions.HTTPError as err:
|
78 |
print(f"HTTP error occurred: {err}")
|
|
|
97 |
return None
|
98 |
|
99 |
# Example usage
|
100 |
+
# audio_translator = AudioTranslation()
|
101 |
+
# transcription = audio_translator.transcribe_audio("voice_test_1.mp3")
|
102 |
+
# translation_result = audio_translator.translate_sentence("rw", "en","MULTI-rw-en","", transcription)
|
103 |
+
# print(translation_result)
|
104 |
'''
|
105 |
alternative models:
|
106 |
https://huggingface.co/facebook/nllb-200-3.3B
|
evaluation.py
CHANGED
@@ -17,4 +17,4 @@ def evaluate_predictions(filename):
|
|
17 |
print("Classification Report:\n", class_report)
|
18 |
|
19 |
# Call the function with the path to your CSV file
|
20 |
-
evaluate_predictions('predictions.csv')
|
|
|
17 |
print("Classification Report:\n", class_report)
|
18 |
|
19 |
# Call the function with the path to your CSV file
|
20 |
+
# evaluate_predictions('predictions.csv')
|
main.py
CHANGED
@@ -37,6 +37,9 @@ def process_audio_files(directories):
|
|
37 |
audio_files = list_audio_files(f"{directory}/")
|
38 |
for file_path in audio_files:
|
39 |
transc = audio_translator.transcribe_audio(file_path)
|
|
|
|
|
|
|
40 |
translation_result = audio_translator.translate_sentence("rw", "en", "MULTI-rw-en", "", transc)
|
41 |
translation_text = translation_result #.get('translatedText') if translation_result else "Translation Failed"
|
42 |
|
|
|
37 |
audio_files = list_audio_files(f"{directory}/")
|
38 |
for file_path in audio_files:
|
39 |
transc = audio_translator.transcribe_audio(file_path)
|
40 |
+
print(file_path)
|
41 |
+
print('transcription')
|
42 |
+
print(transc)
|
43 |
translation_result = audio_translator.translate_sentence("rw", "en", "MULTI-rw-en", "", transc)
|
44 |
translation_text = translation_result #.get('translatedText') if translation_result else "Translation Failed"
|
45 |
|