cyberspyde commited on
Commit
1203715
1 Parent(s): e2b3949
Files changed (3) hide show
  1. Dockerfile +22 -0
  2. main.py +25 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN apt-get -y update
10
+
11
+ RUN useradd -m -u 1000 user
12
+
13
+ USER user
14
+
15
+ ENV HOME=/home/user \
16
+ PATH=/home/user/.local/bin:$PATH
17
+
18
+ WORKDIR $HOME/app
19
+
20
+ COPY --chown=user . $HOME/app
21
+
22
+ CMD ["python", "main.py", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
3
+ from transformers import pipeline
4
+
5
+ app = Flask(__name__)
6
+ model = AutoModelForSpeechSeq2Seq.from_pretrained("GitNazarov/whisper-small-pt-3-uz")
7
+ processor = AutoProcessor.from_pretrained("GitNazarov/whisper-small-pt-3-uz")
8
+
9
+ @app.route('/', methods=['GET'])
10
+ def index():
11
+ return jsonify({"message": "Welcome to whisper uz!"})
12
+
13
+ @app.route('/transcribe', methods=['POST'])
14
+ def transcribe():
15
+ data = request.json['data']
16
+ inputs = processor(data, return_tensors="pt", sampling_rate=16000, max_new_tokens=100)
17
+ input_features = inputs.input_features
18
+ generated_ids = model.generate(inputs=input_features)
19
+
20
+ transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
21
+ transcription = ''.join(transcription)
22
+ return str(transcription), {'Content-Type': 'application/json'}
23
+
24
+ if __name__ == '__main__':
25
+ app.run(host='0.0.0.0', port=7860)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask
2
+ transformers