Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,3 @@
|
|
1 |
-
#Install CLIP-Interrogator-2.1
|
2 |
-
|
3 |
-
import os, subprocess
|
4 |
-
import torch
|
5 |
-
|
6 |
-
def setup():
|
7 |
-
install_cmds = [
|
8 |
-
['pip', 'install', '-e', 'git+https://github.com/pharmapsychotic/BLIP.git@lib#egg=blip'],
|
9 |
-
['git', 'clone', '-b', 'open-clip', 'https://github.com/pharmapsychotic/clip-interrogator.git']
|
10 |
-
]
|
11 |
-
for cmd in install_cmds:
|
12 |
-
print(subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf-8'))
|
13 |
-
|
14 |
-
setup()
|
15 |
-
|
16 |
-
# download cache files
|
17 |
-
print("Download preprocessed cache files...")
|
18 |
-
CACHE_URLS = [
|
19 |
-
'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_artists.pkl',
|
20 |
-
'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_flavors.pkl',
|
21 |
-
'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_mediums.pkl',
|
22 |
-
'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_movements.pkl',
|
23 |
-
'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_trendings.pkl',
|
24 |
-
]
|
25 |
-
os.makedirs('cache', exist_ok=True)
|
26 |
-
for url in CACHE_URLS:
|
27 |
-
print(subprocess.run(['wget', url, '-P', 'cache'], stdout=subprocess.PIPE).stdout.decode('utf-8'))
|
28 |
-
|
29 |
-
import sys
|
30 |
-
sys.path.append('src/blip')
|
31 |
-
sys.path.append('clip-interrogator')
|
32 |
-
|
33 |
-
import gradio as gr
|
34 |
-
from clip_interrogator import Config, Interrogator
|
35 |
-
|
36 |
-
config = Config()
|
37 |
-
config.device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
38 |
-
config.blip_offload = False if torch.cuda.is_available() else True
|
39 |
-
config.chunk_size = 2048
|
40 |
-
config.flavor_intermediate_count = 512
|
41 |
-
config.blip_num_beams = 64
|
42 |
-
|
43 |
-
ci = Interrogator(config)
|
44 |
-
|
45 |
-
def img_to_text(image, mode, best_max_flavors):
|
46 |
-
image = image.convert('RGB')
|
47 |
-
if mode == 'best':
|
48 |
-
|
49 |
-
prompt_result = ci.interrogate(image, max_flavors=int(best_max_flavors))
|
50 |
-
|
51 |
-
print("mode best: " + prompt_result)
|
52 |
-
|
53 |
-
return prompt_result, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
54 |
-
|
55 |
-
elif mode == 'classic':
|
56 |
-
|
57 |
-
prompt_result = ci.interrogate_classic(image)
|
58 |
-
|
59 |
-
print("mode classic: " + prompt_result)
|
60 |
-
|
61 |
-
return prompt_result, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
62 |
-
|
63 |
-
else:
|
64 |
-
|
65 |
-
prompt_result = ci.interrogate_fast(image)
|
66 |
-
|
67 |
-
print("mode fast: " + prompt_result)
|
68 |
-
|
69 |
-
return prompt_result, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
70 |
-
|
71 |
|
72 |
|
73 |
from PIL import Image
|
@@ -97,7 +27,7 @@ import mutagen
|
|
97 |
from mutagen.mp3 import MP3
|
98 |
from mutagen.wave import WAVE
|
99 |
|
100 |
-
|
101 |
text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
|
102 |
|
103 |
language_translation_model = hub.Module(name='baidu_translate')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
|
3 |
from PIL import Image
|
|
|
27 |
from mutagen.mp3 import MP3
|
28 |
from mutagen.wave import WAVE
|
29 |
|
30 |
+
img_to_text = gr.Blocks.load(name="spaces/fffiloni/CLIP-Interrogator-2")
|
31 |
text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
|
32 |
|
33 |
language_translation_model = hub.Module(name='baidu_translate')
|