manasch commited on
Commit
6af123c
·
verified ·
1 Parent(s): 8c914fd

Regex match valid ngrok endpoints

Browse files
Files changed (1) hide show
  1. utils/audio_palette.py +8 -6
utils/audio_palette.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import typing
2
  from datetime import datetime, timezone, timedelta
3
 
@@ -26,6 +27,7 @@ class AudioPalette:
26
  "Medium": "medium",
27
  "Slow": "low"
28
  }
 
29
 
30
  def prompt_construction(self, caption: str, pace: str, sentiment: typing.Union[str, None], instrument: typing.Union[str, None], first: bool = True):
31
  instrument = instrument if instrument is not None else ""
@@ -41,9 +43,9 @@ class AudioPalette:
41
  return prompt
42
 
43
  def generate_single(self, input_image: PIL.Image.Image, instrument: typing.Union[str, None], ngrok_endpoint: typing.Union[str, None]):
44
- if not ngrok_endpoint:
45
- print(f"[{now()}] ngrok endpoint missing")
46
- raise Error("ngrok endpoint missing")
47
  print(f"[{now()}] {ngrok_endpoint}")
48
 
49
  pace = self.pace_model.predict(input_image)
@@ -90,9 +92,9 @@ class AudioPalette:
90
  return file_name
91
 
92
  def generate_multiple(self, file_paths: typing.List[str], instrument: typing.Union[str, None], ngrok_endpoint: typing.Union[str, None]):
93
- if not ngrok_endpoint:
94
- print(f"[{now()}] ngrok endpoint missing")
95
- raise Error("ngrok endpoint missing")
96
  print(f"[{now()}] {ngrok_endpoint}")
97
 
98
  images = [Image.open(image_path) for image_path in file_paths]
 
1
+ import re
2
  import typing
3
  from datetime import datetime, timezone, timedelta
4
 
 
27
  "Medium": "medium",
28
  "Slow": "low"
29
  }
30
+ self.ngrok_url_pattern = re.compile("https:\/\/[a-z0-9\-]+\.ngrok\.io\/")
31
 
32
  def prompt_construction(self, caption: str, pace: str, sentiment: typing.Union[str, None], instrument: typing.Union[str, None], first: bool = True):
33
  instrument = instrument if instrument is not None else ""
 
43
  return prompt
44
 
45
  def generate_single(self, input_image: PIL.Image.Image, instrument: typing.Union[str, None], ngrok_endpoint: typing.Union[str, None]):
46
+ if not self.ngrok_url_pattern.search(ngrok_endpoint):
47
+ print(f"[{now()}] Invalid ngrok endpoint - {ngrok_endpoint}")
48
+ raise Error(f"Invalid ngrok endpoint - {ngrok_endpoint}")
49
  print(f"[{now()}] {ngrok_endpoint}")
50
 
51
  pace = self.pace_model.predict(input_image)
 
92
  return file_name
93
 
94
  def generate_multiple(self, file_paths: typing.List[str], instrument: typing.Union[str, None], ngrok_endpoint: typing.Union[str, None]):
95
+ if not self.ngrok_url_pattern.search(ngrok_endpoint):
96
+ print(f"[{now()}] Invalid ngrok endpoint - {ngrok_endpoint}")
97
+ raise Error(f"Invalid ngrok endpoint - {ngrok_endpoint}")
98
  print(f"[{now()}] {ngrok_endpoint}")
99
 
100
  images = [Image.open(image_path) for image_path in file_paths]