VenkateshRoshan commited on
Commit
6afd1f4
·
1 Parent(s): f461359

Initial Commit

Browse files
Dog.jpg DELETED
Binary file (246 kB)
 
dockerfile → __init__.py RENAMED
File without changes
__pycache__/__init__.cpython-310.pyc ADDED
Binary file (155 Bytes). View file
 
__pycache__/app.cpython-310.pyc ADDED
Binary file (2.1 kB). View file
 
butterfly.png DELETED
Binary file (407 kB)
 
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
  git+https://github.com/openai/whisper.git
2
  transformers
3
  requests
4
- huggingface_hub
 
 
 
1
  git+https://github.com/openai/whisper.git
2
  transformers
3
  requests
4
+ huggingface_hub
5
+ pytest
6
+ gradio
setup.sh DELETED
@@ -1,16 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Define the path to the virtual environment
4
- VENV_DIR="path/to/venv"
5
-
6
- # Create the virtual environment
7
- python3 -m venv $VENV_DIR
8
-
9
- # Activate the virtual environment
10
- source $VENV_DIR/bin/activate
11
-
12
- # Install required packages
13
- pip3 install -r requirements.txt
14
-
15
- # Message to confirm installation completion
16
- echo "Python environment setup is complete, and packages are installed."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/__pycache__/test_module.cpython-310-pytest-8.3.3.pyc ADDED
Binary file (2.7 kB). View file
 
tests/sample.wav ADDED
Binary file (91.3 kB). View file
 
tests/test_module.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import os
3
+ import sys
4
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
5
+ from unittest.mock import patch
6
+ from app import transcribe
7
+
8
+ # Add the root directory to the Python path so we can import app.py
9
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
10
+
11
+ # Test to check if necessary libraries are installed
12
+ def test_libraries_installed():
13
+ try:
14
+ import requests
15
+ import gradio as gr
16
+ import transformers
17
+ import time
18
+ import os
19
+ import tempfile
20
+ from huggingface_hub import InferenceClient
21
+ except ImportError as e:
22
+ pytest.fail(f"Library not installed: {e}")
23
+
24
+ # Define a constant for the audio file to be used in tests
25
+ AUDIO_FILE = "tests/sample.wav"
26
+
27
+ # Fixture to check if the audio file exists
28
+ @pytest.fixture
29
+ def check_audio_file():
30
+ print(f"Checking if audio file {AUDIO_FILE} exists...")
31
+ assert os.path.exists(AUDIO_FILE), f"Audio file {AUDIO_FILE} does not exist."
32
+ return AUDIO_FILE
33
+
34
+ # Need to login Hugging Face account to use the API
35
+ # # Test the transcribe function using the API
36
+ # @patch('app.InferenceClient') # Mock the InferenceClient to simulate API response
37
+ # def test_transcribe_api(mock_client, check_audio_file):
38
+ # # Mocking the return value of the API call
39
+ # mock_client.return_value.automatic_speech_recognition.return_value.text = "This is a test transcription."
40
+
41
+ # # Call the transcribe function with the mock and use_api=True
42
+ # result, time_taken = transcribe(check_audio_file, use_api=True)
43
+
44
+ # # Assert the mocked transcription matches the expected result
45
+ # assert result == "This is a test transcription."
46
+ # assert time_taken.startswith('Using API it took: ')
47
+
48
+ # Test the transcribe function using the local pipeline (when use_api=False)
49
+ @patch('app.pipeline') # Mock the local pipeline function
50
+ def test_transcribe_local(mock_pipeline, check_audio_file):
51
+ # Mocking the local transcription
52
+ mock_pipeline.return_value.return_value['text'] = "Now go away or I shall taunt you a second time!"
53
+
54
+ # Call the transcribe function with the mock and use_api=False
55
+ result, time_taken = transcribe(check_audio_file, use_api=False)
56
+
57
+ # print(result)
58
+
59
+ # Assert the mocked transcription matches the expected result
60
+ assert result.strip() == "Now go away or I shall taunt you a second time!"
61
+ assert time_taken.startswith('Using local pipeline it took: ')
62
+