Update app.py
Browse files
app.py
CHANGED
|
@@ -3,30 +3,7 @@ from share_btn import community_icon_html, loading_icon_html, share_js
|
|
| 3 |
import os, subprocess
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
# install_cmds = [
|
| 8 |
-
# ['pip', 'install', 'ftfy', 'gradio', 'regex', 'tqdm', 'transformers==4.21.2', 'timm', 'fairscale', 'requests'],
|
| 9 |
-
# ['pip', 'install', 'open_clip_torch'],
|
| 10 |
-
# ['pip', 'install', '-e', 'git+https://github.com/pharmapsychotic/BLIP.git@lib#egg=blip'],
|
| 11 |
-
# ['git', 'clone', '-b', 'open-clip', 'https://github.com/pharmapsychotic/clip-interrogator.git']
|
| 12 |
-
# ]
|
| 13 |
-
# for cmd in install_cmds:
|
| 14 |
-
# print(subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf-8'))
|
| 15 |
-
|
| 16 |
-
# setup()
|
| 17 |
-
|
| 18 |
-
# download cache files
|
| 19 |
-
# print("Download preprocessed cache files...")
|
| 20 |
-
# CACHE_URLS = [
|
| 21 |
-
# 'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_artists.pkl',
|
| 22 |
-
# 'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_flavors.pkl',
|
| 23 |
-
# 'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_mediums.pkl',
|
| 24 |
-
# 'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_movements.pkl',
|
| 25 |
-
# 'https://huggingface.co/pharma/ci-preprocess/resolve/main/ViT-H-14_laion2b_s32b_b79k_trendings.pkl',
|
| 26 |
-
# ]
|
| 27 |
-
# os.makedirs('cache', exist_ok=True)
|
| 28 |
-
# for url in CACHE_URLS:
|
| 29 |
-
# print(subprocess.run(['wget', url, '-P', 'cache'], stdout=subprocess.PIPE).stdout.decode('utf-8'))
|
| 30 |
|
| 31 |
import sys
|
| 32 |
sys.path.append('src/blip')
|
|
@@ -59,8 +36,6 @@ def inference(input_images, mode, best_max_flavors):
|
|
| 59 |
prompt_texts.append(prompt_result['prompt']) # Extract the prompt text
|
| 60 |
return prompt_texts
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
title = """
|
| 65 |
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
| 66 |
<div
|
|
@@ -149,8 +124,8 @@ a {text-decoration-line: underline; font-weight: 600;}
|
|
| 149 |
height: 100% !important;
|
| 150 |
font-size: 17px !important;
|
| 151 |
}
|
| 152 |
-
|
| 153 |
'''
|
|
|
|
| 154 |
with gr.Blocks(css=css) as block:
|
| 155 |
with gr.Column(elem_id="col-container"):
|
| 156 |
gr.HTML(title)
|
|
@@ -163,9 +138,11 @@ with gr.Blocks(css=css) as block:
|
|
| 163 |
submit_btn = gr.Button("Submit")
|
| 164 |
|
| 165 |
# Display the prompt texts
|
| 166 |
-
gallery = gr.
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
| 169 |
)
|
| 170 |
|
| 171 |
with gr.Group(elem_id="share-btn-container"):
|
|
@@ -175,4 +152,3 @@ with gr.Blocks(css=css) as block:
|
|
| 175 |
submit_btn.click(fn=inference, inputs=[input_image,mode_input,flavor_input], outputs=[gallery], api_name="clipi2")
|
| 176 |
|
| 177 |
block.queue(max_size=32,concurrency_count=10).launch(show_api=False)
|
| 178 |
-
|
|
|
|
| 3 |
import os, subprocess
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
# (Code for setup and downloading cache files)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
import sys
|
| 9 |
sys.path.append('src/blip')
|
|
|
|
| 36 |
prompt_texts.append(prompt_result['prompt']) # Extract the prompt text
|
| 37 |
return prompt_texts
|
| 38 |
|
|
|
|
|
|
|
| 39 |
title = """
|
| 40 |
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
| 41 |
<div
|
|
|
|
| 124 |
height: 100% !important;
|
| 125 |
font-size: 17px !important;
|
| 126 |
}
|
|
|
|
| 127 |
'''
|
| 128 |
+
|
| 129 |
with gr.Blocks(css=css) as block:
|
| 130 |
with gr.Column(elem_id="col-container"):
|
| 131 |
gr.HTML(title)
|
|
|
|
| 138 |
submit_btn = gr.Button("Submit")
|
| 139 |
|
| 140 |
# Display the prompt texts
|
| 141 |
+
gallery = gr.HTML(
|
| 142 |
+
src="{{' '.join(outputs['prompt_texts'])}}",
|
| 143 |
+
type="div",
|
| 144 |
+
label="Outputs",
|
| 145 |
+
elem_id="gallery"
|
| 146 |
)
|
| 147 |
|
| 148 |
with gr.Group(elem_id="share-btn-container"):
|
|
|
|
| 152 |
submit_btn.click(fn=inference, inputs=[input_image,mode_input,flavor_input], outputs=[gallery], api_name="clipi2")
|
| 153 |
|
| 154 |
block.queue(max_size=32,concurrency_count=10).launch(show_api=False)
|
|
|