fffiloni commited on
Commit
5d86653
·
verified ·
1 Parent(s): 4998b03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -3,20 +3,35 @@ import sys
3
  import subprocess
4
  import torch
5
 
6
- # Clone only the runtime source repo if missing
7
- if not os.path.exists("clip-interrogator"):
8
- subprocess.run(
9
- [
10
- "git",
11
- "clone",
12
- "-b",
13
- "open-clip",
14
- "https://github.com/pharmapsychotic/clip-interrogator.git",
15
- ],
16
- check=True,
17
- )
18
 
19
- # Download cache files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  print("Download preprocessed cache files...")
21
 
22
  CACHE_URLS = [
@@ -32,8 +47,6 @@ os.makedirs("cache", exist_ok=True)
32
  for url in CACHE_URLS:
33
  subprocess.run(["wget", "-nc", url, "-P", "cache"], check=False)
34
 
35
- sys.path.append("src/blip")
36
- sys.path.append("clip-interrogator")
37
 
38
  import gradio as gr
39
  from clip_interrogator import Config, Interrogator
 
3
  import subprocess
4
  import torch
5
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ def clone_if_missing(path, repo, branch=None):
8
+ if os.path.exists(path):
9
+ return
10
+
11
+ cmd = ["git", "clone"]
12
+ if branch:
13
+ cmd += ["-b", branch]
14
+ cmd += [repo, path]
15
+
16
+ subprocess.run(cmd, check=True)
17
+
18
+
19
+ clone_if_missing(
20
+ "src/blip",
21
+ "https://github.com/pharmapsychotic/BLIP.git",
22
+ branch="lib",
23
+ )
24
+
25
+ clone_if_missing(
26
+ "clip-interrogator",
27
+ "https://github.com/pharmapsychotic/clip-interrogator.git",
28
+ branch="open-clip",
29
+ )
30
+
31
+ sys.path.append("src/blip")
32
+ sys.path.append("clip-interrogator")
33
+
34
+
35
  print("Download preprocessed cache files...")
36
 
37
  CACHE_URLS = [
 
47
  for url in CACHE_URLS:
48
  subprocess.run(["wget", "-nc", url, "-P", "cache"], check=False)
49
 
 
 
50
 
51
  import gradio as gr
52
  from clip_interrogator import Config, Interrogator