NeeravS commited on
Commit
f7b5887
·
verified ·
1 Parent(s): 5aa6ebe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -31,6 +31,13 @@ ip_access_records = defaultdict(lambda: {
31
  'last_access_time': None
32
  })
33
 
 
 
 
 
 
 
 
34
  SESSION_TIMEOUT = timedelta(hours=1)
35
 
36
  # Function to log API access attempts
@@ -189,9 +196,13 @@ def analyze_video(video_file, captcha_input, captcha_solution, request: gr.Reque
189
  }
190
  return output
191
 
 
 
 
192
  except Exception as e:
193
  logging.error(f"Error during analysis: {e}")
194
  return {"error": "An error occurred during video analysis. Please check your input and try again."}
 
195
 
196
  # Interface with CAPTCHA after video upload
197
  def main_interface():
 
31
  'last_access_time': None
32
  })
33
 
34
+ AUTHORIZED_API_KEY = os.getenv("HF_API_KEY")
35
+
36
+ def is_authorized(request: gr.Request):
37
+ """Checks if the request includes the correct API key."""
38
+ api_key = request.headers.get("API-Key")
39
+ return api_key == AUTHORIZED_API_KEY
40
+
41
  SESSION_TIMEOUT = timedelta(hours=1)
42
 
43
  # Function to log API access attempts
 
196
  }
197
  return output
198
 
199
+ if not is_authorized(request):
200
+ return {"error": "Unauthorized access. Please provide a valid API key."}
201
+
202
  except Exception as e:
203
  logging.error(f"Error during analysis: {e}")
204
  return {"error": "An error occurred during video analysis. Please check your input and try again."}
205
+
206
 
207
  # Interface with CAPTCHA after video upload
208
  def main_interface():