Daniel Huynh commited on
Commit
2a0eb38
1 Parent(s): 8191c52

feat: enable api key check

Browse files
Files changed (1) hide show
  1. app.py +8 -19
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import base64
3
  import requests
4
  import uuid
 
5
 
6
  USER_ID = str(uuid.uuid4())
7
  SERVER_URL = "https://lavague.mithrilsecurity.io"
@@ -17,7 +18,8 @@ title = """
17
 
18
  def exec_code_req(url, query):
19
  headers = {
20
- "X-User-ID": USER_ID # Include the X-User-ID header for authentication
 
21
  }
22
  try:
23
  response = requests.post(SERVER_URL + "/execute_req", json={"url": url, "query": query}, headers=headers)
@@ -28,23 +30,10 @@ def exec_code_req(url, query):
28
  except requests.RequestException as e:
29
  return {"error": str(e)}
30
 
31
- def get_html(url):
32
  headers = {
33
- "X-User-ID": USER_ID # Include the X-User-ID header for authentication
34
- }
35
- try:
36
- response = requests.post(SERVER_URL + "/get_html", json={"url": url}, headers=headers)
37
- if response.status_code == 200:
38
- return response.json()
39
- else:
40
- return {"error": f"Failed with status code {response.status_code}"}
41
- except requests.RequestException as e:
42
- return {"error": str(e)}
43
-
44
-
45
- def send_request(url):
46
- headers = {
47
- "X-User-ID": USER_ID # Include the X-User-ID header for authentication
48
  }
49
  try:
50
  response = requests.get(SERVER_URL + "/screenshot", params={"url": url}, headers=headers)
@@ -56,7 +45,7 @@ def send_request(url):
56
  return {"error": str(e)}
57
 
58
  def process_url(url):
59
- r = send_request(url)
60
  f = open("screenshot.png", "wb")
61
  scr = base64.b64decode(r["result"])
62
  f.write(scr)
@@ -79,7 +68,7 @@ def exec_code(code, source_nodes, full_code, url, query):
79
  return output, code, html, status, full_code, url, source_nodes
80
 
81
  def update_image_display(img, url):
82
- r = send_request(url)
83
  f = open("screenshot.png", "wb")
84
  scr = base64.b64decode(r["result"])
85
  f.write(scr)
 
2
  import base64
3
  import requests
4
  import uuid
5
+ import os
6
 
7
  USER_ID = str(uuid.uuid4())
8
  SERVER_URL = "https://lavague.mithrilsecurity.io"
 
18
 
19
  def exec_code_req(url, query):
20
  headers = {
21
+ "X-User-ID": USER_ID, # Include the X-User-ID header for authentication
22
+ "X-API-Key": os.environ['API_KEY']
23
  }
24
  try:
25
  response = requests.post(SERVER_URL + "/execute_req", json={"url": url, "query": query}, headers=headers)
 
30
  except requests.RequestException as e:
31
  return {"error": str(e)}
32
 
33
+ def get_screenshot_req(url):
34
  headers = {
35
+ "X-User-ID": USER_ID, # Include the X-User-ID header for authentication
36
+ "X-API-Key": os.environ['API_KEY']
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
  try:
39
  response = requests.get(SERVER_URL + "/screenshot", params={"url": url}, headers=headers)
 
45
  return {"error": str(e)}
46
 
47
  def process_url(url):
48
+ r = get_screenshot_req(url)
49
  f = open("screenshot.png", "wb")
50
  scr = base64.b64decode(r["result"])
51
  f.write(scr)
 
68
  return output, code, html, status, full_code, url, source_nodes
69
 
70
  def update_image_display(img, url):
71
+ r = get_screenshot_req(url)
72
  f = open("screenshot.png", "wb")
73
  scr = base64.b64decode(r["result"])
74
  f.write(scr)