Tri4 commited on
Commit
1c03892
·
verified ·
1 Parent(s): a414737

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -4
main.py CHANGED
@@ -1,8 +1,9 @@
1
  from flask import Flask, request, jsonify
2
  from datetime import datetime
3
  import whisper
4
- import os
5
  import time
 
 
6
 
7
 
8
  app = Flask(__name__)
@@ -16,6 +17,19 @@ print("Loading Whisper model...", flush=True)
16
  model = whisper.load_model("tiny")
17
  print("Whisper model loaded.", flush=True)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def transcribe(audio_path):
20
  print(f"Transcribing audio from: {audio_path}", flush=True)
21
 
@@ -45,7 +59,7 @@ def transcribe(audio_path):
45
  @app.route('/transcribe', methods=['POST'])
46
  def transcribe_audio():
47
  # Record the time when the request was received
48
- request_received_time = datetime.now()
49
  print(f"Received request at /transcribe at {request_received_time}", flush=True)
50
 
51
  if 'audio' not in request.files:
@@ -81,8 +95,8 @@ def transcribe_audio():
81
  print(f"Audio file removed from: {audio_path}", flush=True)
82
 
83
  # Record the time when the response is being sent
84
- response_sent_time = datetime.now()
85
-
86
  # Return the transcription, detected language, and timing information
87
  print(f"Transcription: {transcription}, Language: {language}", flush=True)
88
  return jsonify({
 
1
  from flask import Flask, request, jsonify
2
  from datetime import datetime
3
  import whisper
 
4
  import time
5
+ import pytz
6
+ import os
7
 
8
 
9
  app = Flask(__name__)
 
17
  model = whisper.load_model("tiny")
18
  print("Whisper model loaded.", flush=True)
19
 
20
+ # Get time of request
21
+ def get_time():
22
+ nairobi_timezone = pytz.timezone('Africa/Nairobi')
23
+ current_time_nairobi = datetime.now(nairobi_timezone)
24
+
25
+ curr_day = current_time_nairobi.strftime('%A')
26
+ curr_date = current_time_nairobi.strftime('%Y-%m-%d')
27
+ curr_time = current_time_nairobi.strftime('%H:%M:%S')
28
+
29
+ full_date = f"{curr_day} | {curr_date} | {curr_time}"
30
+ return full_date, curr_time
31
+
32
+
33
  def transcribe(audio_path):
34
  print(f"Transcribing audio from: {audio_path}", flush=True)
35
 
 
59
  @app.route('/transcribe', methods=['POST'])
60
  def transcribe_audio():
61
  # Record the time when the request was received
62
+ request_received_time = get_time()[0]
63
  print(f"Received request at /transcribe at {request_received_time}", flush=True)
64
 
65
  if 'audio' not in request.files:
 
95
  print(f"Audio file removed from: {audio_path}", flush=True)
96
 
97
  # Record the time when the response is being sent
98
+ response_sent_time = get_time()[0]
99
+
100
  # Return the transcription, detected language, and timing information
101
  print(f"Transcription: {transcription}, Language: {language}", flush=True)
102
  return jsonify({