vineet124jig commited on
Commit
36ce10c
·
verified ·
1 Parent(s): 54199ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -13,8 +13,8 @@ headers = {
13
 
14
  # Rate limiting configuration
15
  request_times = defaultdict(list)
16
- MAX_REQUESTS = 1 # Maximum requests per time window
17
- TIME_WINDOW = 60 # Time window in seconds
18
 
19
  def get_real_ip(request: gr.Request):
20
  """Extract real IP address using x-forwarded-for header or fallback"""
@@ -35,10 +35,7 @@ def check_rate_limit(request: gr.Request):
35
 
36
  ip = get_real_ip(request)
37
  now = time.time()
38
-
39
- print(f"Ip: {ip}")
40
- print(f"Now: {now}")
41
- print(f"Request times: {request_times[ip]}")
42
  # Clean up old timestamps outside the time window
43
  request_times[ip] = [t for t in request_times[ip] if now - t < TIME_WINDOW]
44
 
@@ -54,9 +51,9 @@ def check_rate_limit(request: gr.Request):
54
  return True, ""
55
 
56
 
57
- def transcribe_audio(input_type, audio_url, file_store_key, language):
58
  """Transcribe audio using JigsawStack Speech-to-Text API"""
59
-
60
  # Check rate limit first
61
  rate_limit_ok, rate_limit_msg = check_rate_limit(request)
62
  if not rate_limit_ok:
@@ -81,6 +78,7 @@ def transcribe_audio(input_type, audio_url, file_store_key, language):
81
  )
82
  response.raise_for_status()
83
  result = response.json()
 
84
  if not result.get("success"):
85
  error_msg = f"Error: API call failed - {result.get('message', 'Unknown error')}"
86
  return error_msg, ""
@@ -97,6 +95,7 @@ with gr.Blocks() as demo:
97
  <h1 style='font-size:2.2em; margin-bottom: 0.2em;'>Speech-to-Text Transcription</h1>
98
  <p style='font-size:1.2em; margin-top: 0;'>Transcribe video and audio files with ease leveraging Whisper large V3 AI model.</p>
99
  <p style='font-size:1em; margin-top: 0.5em;'>Supported formats: MP3, WAV, M4A, FLAC, AAC, OGG, WEBM. Max file size: 100MB, Max duration: 4 hours.</p>
 
100
  </div>
101
  """)
102
  with gr.Row():
 
13
 
14
  # Rate limiting configuration
15
  request_times = defaultdict(list)
16
+ MAX_REQUESTS = 20 # Maximum requests per time window
17
+ TIME_WINDOW = 3600 # Time window in seconds (1 hour)
18
 
19
  def get_real_ip(request: gr.Request):
20
  """Extract real IP address using x-forwarded-for header or fallback"""
 
35
 
36
  ip = get_real_ip(request)
37
  now = time.time()
38
+
 
 
 
39
  # Clean up old timestamps outside the time window
40
  request_times[ip] = [t for t in request_times[ip] if now - t < TIME_WINDOW]
41
 
 
51
  return True, ""
52
 
53
 
54
+ def transcribe_audio(input_type, audio_url, file_store_key, language, request: gr.Request):
55
  """Transcribe audio using JigsawStack Speech-to-Text API"""
56
+
57
  # Check rate limit first
58
  rate_limit_ok, rate_limit_msg = check_rate_limit(request)
59
  if not rate_limit_ok:
 
78
  )
79
  response.raise_for_status()
80
  result = response.json()
81
+
82
  if not result.get("success"):
83
  error_msg = f"Error: API call failed - {result.get('message', 'Unknown error')}"
84
  return error_msg, ""
 
95
  <h1 style='font-size:2.2em; margin-bottom: 0.2em;'>Speech-to-Text Transcription</h1>
96
  <p style='font-size:1.2em; margin-top: 0;'>Transcribe video and audio files with ease leveraging Whisper large V3 AI model.</p>
97
  <p style='font-size:1em; margin-top: 0.5em;'>Supported formats: MP3, WAV, M4A, FLAC, AAC, OGG, WEBM. Max file size: 100MB, Max duration: 4 hours.</p>
98
+ <p style='font-size:0.9em; margin-top: 0.5em; color: #666;'>Rate limit: {MAX_REQUESTS} requests per {TIME_WINDOW} seconds per IP</p>
99
  </div>
100
  """)
101
  with gr.Row():