Spaces:
Running
on
Zero
Running
on
Zero
Update API
Browse files- app.py +5 -1
- examples/banana.jpg +0 -0
- examples/cat.jpeg +0 -0
- examples/city.jpg +0 -0
- examples/dog.jpg +0 -0
- examples/duck.jpg +0 -3
- examples/duck_hat.jpg +0 -0
- examples/example1.jpg +0 -0
- examples/example2.jpg +0 -0
- examples/example3.jpg +0 -0
- examples/example4.jpg +0 -0
- examples/fire.jpg +0 -0
- examples/mouse.jpg +0 -0
- examples/oranges.jpg +0 -0
- examples/pig.jpg +0 -0
- examples/rabbit.jpg +0 -0
- examples/strawberries.jpg +0 -0
- model/matchmaker.py +2 -4
- model/model_manager.py +36 -15
- model/models/__init__.py +46 -28
- model/models/huggingface_models.py +15 -10
- model/models/openai_api_models.py +30 -0
- model/models/replicate_api_models.py +175 -0
- requirements.txt +1 -0
- serve/Ksort.py +31 -57
- serve/gradio_web.py +78 -86
- serve/update_skill.py +12 -5
- serve/upload.py +21 -1
- serve/utils.py +53 -11
app.py
CHANGED
@@ -7,7 +7,11 @@ from pathlib import Path
|
|
7 |
from serve.constants import SERVER_PORT, ROOT_PATH, ELO_RESULTS_DIR
|
8 |
|
9 |
def build_combine_demo(models, elo_results_file, leaderboard_table_file):
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
with gr.Blocks(
|
12 |
title="Play with Open Vision Models",
|
13 |
theme=gr.themes.Default(),
|
|
|
7 |
from serve.constants import SERVER_PORT, ROOT_PATH, ELO_RESULTS_DIR
|
8 |
|
9 |
def build_combine_demo(models, elo_results_file, leaderboard_table_file):
|
10 |
+
# gr.themes.Default(),
|
11 |
+
# gr.themes.Soft(),
|
12 |
+
# gr.Theme.from_hub('gary109/HaleyCH_Theme'),
|
13 |
+
# gr.Theme.from_hub('EveryPizza/Cartoony-Gradio-Theme')
|
14 |
+
# gr.themes.Default(primary_hue="red", secondary_hue="pink")
|
15 |
with gr.Blocks(
|
16 |
title="Play with Open Vision Models",
|
17 |
theme=gr.themes.Default(),
|
examples/banana.jpg
DELETED
Binary file (352 kB)
|
|
examples/cat.jpeg
DELETED
Binary file (390 kB)
|
|
examples/city.jpg
DELETED
Binary file (455 kB)
|
|
examples/dog.jpg
DELETED
Binary file (330 kB)
|
|
examples/duck.jpg
DELETED
Git LFS Details
|
examples/duck_hat.jpg
DELETED
Binary file (225 kB)
|
|
examples/example1.jpg
ADDED
examples/example2.jpg
ADDED
examples/example3.jpg
ADDED
examples/example4.jpg
ADDED
examples/fire.jpg
DELETED
Binary file (336 kB)
|
|
examples/mouse.jpg
DELETED
Binary file (234 kB)
|
|
examples/oranges.jpg
DELETED
Binary file (179 kB)
|
|
examples/pig.jpg
DELETED
Binary file (37.9 kB)
|
|
examples/rabbit.jpg
DELETED
Binary file (209 kB)
|
|
examples/strawberries.jpg
DELETED
Binary file (249 kB)
|
|
model/matchmaker.py
CHANGED
@@ -61,7 +61,8 @@ def matchmaker(num_players, k_group=4):
|
|
61 |
ratings, comparison_counts, total_comparisons = load_json_via_sftp()
|
62 |
|
63 |
# Randomly select a player
|
64 |
-
selected_player = np.random.randint(0, num_players)
|
|
|
65 |
|
66 |
selected_trueskill_score = trueskill_env.expose(ratings[selected_player])
|
67 |
trueskill_scores = np.array([trueskill_env.expose(p) for p in ratings])
|
@@ -75,9 +76,6 @@ def matchmaker(num_players, k_group=4):
|
|
75 |
|
76 |
# Group players
|
77 |
model_ids = [selected_player] + opponents
|
78 |
-
|
79 |
-
from serve.update_skill import Model_ID
|
80 |
-
Model_ID.group = model_ids
|
81 |
|
82 |
return model_ids
|
83 |
|
|
|
61 |
ratings, comparison_counts, total_comparisons = load_json_via_sftp()
|
62 |
|
63 |
# Randomly select a player
|
64 |
+
# selected_player = np.random.randint(0, num_players)
|
65 |
+
selected_player = np.argmin(comparison_counts.sum(axis=1))
|
66 |
|
67 |
selected_trueskill_score = trueskill_env.expose(ratings[selected_player])
|
68 |
trueskill_scores = np.array([trueskill_env.expose(p) for p in ratings])
|
|
|
76 |
|
77 |
# Group players
|
78 |
model_ids = [selected_player] + opponents
|
|
|
|
|
|
|
79 |
|
80 |
return model_ids
|
81 |
|
model/model_manager.py
CHANGED
@@ -7,6 +7,7 @@ import spaces
|
|
7 |
from PIL import Image
|
8 |
from .models import IMAGE_GENERATION_MODELS, IMAGE_EDITION_MODELS, load_pipeline
|
9 |
from .fetch_museum_results import draw_from_imagen_museum, draw2_from_imagen_museum
|
|
|
10 |
|
11 |
class ModelManager:
|
12 |
def __init__(self):
|
@@ -25,7 +26,7 @@ class ModelManager:
|
|
25 |
@spaces.GPU(duration=120)
|
26 |
def generate_image_ig(self, prompt, model_name):
|
27 |
pipe = self.load_model_pipe(model_name)
|
28 |
-
result = pipe(prompt=prompt)
|
29 |
return result
|
30 |
|
31 |
def generate_image_ig_api(self, prompt, model_name):
|
@@ -47,18 +48,23 @@ class ModelManager:
|
|
47 |
# model_names = random.sample([model for model in self.model_ig_list], 4)
|
48 |
from .matchmaker import matchmaker
|
49 |
model_ids = matchmaker(num_players=len(self.model_ig_list))
|
|
|
50 |
model_names = [self.model_ig_list[i] for i in model_ids]
|
|
|
51 |
else:
|
52 |
model_names = [model_A, model_B, model_C, model_D]
|
53 |
|
|
|
|
|
|
|
|
|
|
|
54 |
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
55 |
-
# futures = [executor.submit(self.
|
56 |
-
# else executor.submit(self.generate_image_ig_api, prompt, model) for model in model_names]
|
57 |
# results = [future.result() for future in futures]
|
58 |
|
|
|
59 |
|
60 |
-
results = [self.generate_image_ig(prompt, model) for model in model_names]
|
61 |
-
# results = [future.result() for future in futures]
|
62 |
return results[0], results[1], results[2], results[3], \
|
63 |
model_names[0], model_names[1], model_names[2], model_names[3]
|
64 |
|
@@ -67,23 +73,38 @@ class ModelManager:
|
|
67 |
# model_names = random.sample([model for model in self.model_ig_list], 4)
|
68 |
from .matchmaker import matchmaker
|
69 |
model_ids = matchmaker(num_players=len(self.model_ig_list))
|
|
|
70 |
model_names = [self.model_ig_list[i] for i in model_ids]
|
|
|
71 |
else:
|
72 |
model_names = [model_A, model_B, model_C, model_D]
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
return image_links[0], image_links[1], image_links[2], image_links[3], \
|
86 |
-
model_names[0], model_names[1], model_names[2], model_names[3], prompt_list[0]
|
87 |
|
88 |
def generate_image_ig_parallel(self, prompt, model_A, model_B):
|
89 |
model_names = [model_A, model_B]
|
|
|
7 |
from PIL import Image
|
8 |
from .models import IMAGE_GENERATION_MODELS, IMAGE_EDITION_MODELS, load_pipeline
|
9 |
from .fetch_museum_results import draw_from_imagen_museum, draw2_from_imagen_museum
|
10 |
+
from serve.upload import get_random_mscoco_prompt
|
11 |
|
12 |
class ModelManager:
|
13 |
def __init__(self):
|
|
|
26 |
@spaces.GPU(duration=120)
|
27 |
def generate_image_ig(self, prompt, model_name):
|
28 |
pipe = self.load_model_pipe(model_name)
|
29 |
+
result = pipe(prompt=prompt).images[0]
|
30 |
return result
|
31 |
|
32 |
def generate_image_ig_api(self, prompt, model_name):
|
|
|
48 |
# model_names = random.sample([model for model in self.model_ig_list], 4)
|
49 |
from .matchmaker import matchmaker
|
50 |
model_ids = matchmaker(num_players=len(self.model_ig_list))
|
51 |
+
print(model_ids)
|
52 |
model_names = [self.model_ig_list[i] for i in model_ids]
|
53 |
+
print(model_names)
|
54 |
else:
|
55 |
model_names = [model_A, model_B, model_C, model_D]
|
56 |
|
57 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
58 |
+
futures = [executor.submit(self.generate_image_ig, prompt, model) if model.startswith("huggingface")
|
59 |
+
else executor.submit(self.generate_image_ig_api, prompt, model) for model in model_names]
|
60 |
+
results = [future.result() for future in futures]
|
61 |
+
|
62 |
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
63 |
+
# futures = [executor.submit(self.generate_image_ig_api, prompt, model) for model in model_names]
|
|
|
64 |
# results = [future.result() for future in futures]
|
65 |
|
66 |
+
# results = [self.generate_image_ig(prompt, model) for model in model_names]
|
67 |
|
|
|
|
|
68 |
return results[0], results[1], results[2], results[3], \
|
69 |
model_names[0], model_names[1], model_names[2], model_names[3]
|
70 |
|
|
|
73 |
# model_names = random.sample([model for model in self.model_ig_list], 4)
|
74 |
from .matchmaker import matchmaker
|
75 |
model_ids = matchmaker(num_players=len(self.model_ig_list))
|
76 |
+
print(model_ids)
|
77 |
model_names = [self.model_ig_list[i] for i in model_ids]
|
78 |
+
print(model_names)
|
79 |
else:
|
80 |
model_names = [model_A, model_B, model_C, model_D]
|
81 |
|
82 |
+
prompt = get_random_mscoco_prompt()
|
83 |
+
print(prompt)
|
84 |
+
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
85 |
+
# model_1 = model_names[0].split('_')[1]
|
86 |
+
# model_2 = model_names[1].split('_')[1]
|
87 |
+
# model_3 = model_names[2].split('_')[1]
|
88 |
+
# model_4 = model_names[3].split('_')[1]
|
89 |
+
|
90 |
+
# result_list = draw2_from_imagen_museum("t2i", model_1, model_2, model_3, model_4)
|
91 |
+
# image_links = result_list[0]
|
92 |
+
# prompt_list = result_list[1]
|
93 |
+
# print(prompt_list[0])
|
94 |
+
|
95 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
96 |
+
futures = [executor.submit(self.generate_image_ig, prompt, model) if model.startswith("huggingface")
|
97 |
+
else executor.submit(self.generate_image_ig_api, prompt, model) for model in model_names]
|
98 |
+
results = [future.result() for future in futures]
|
99 |
+
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
100 |
+
# futures = [executor.submit(self.generate_image_ig_api, prompt, model) for model in model_names]
|
101 |
+
# results = [future.result() for future in futures]
|
102 |
|
103 |
+
# results = [self.generate_image_ig_api(prompt, model) for model in model_names]
|
104 |
+
# results = [future.result() for future in futures]
|
105 |
+
return results[0], results[1], results[2], results[3], \
|
106 |
+
model_names[0], model_names[1], model_names[2], model_names[3], prompt
|
107 |
|
|
|
|
|
108 |
|
109 |
def generate_image_ig_parallel(self, prompt, model_A, model_B):
|
110 |
model_names = [model_A, model_B]
|
model/models/__init__.py
CHANGED
@@ -2,35 +2,51 @@ from .imagenhub_models import load_imagenhub_model
|
|
2 |
# from .playground_api import load_playground_model
|
3 |
from .fal_api_models import load_fal_model
|
4 |
# from .videogenhub_models import load_videogenhub_model
|
5 |
-
|
|
|
|
|
6 |
|
7 |
# IMAGE_GENERATION_MODELS = ['huggingface_SD-v1.5_text2image',
|
8 |
# 'huggingface_SD-v2.1_text2image',
|
9 |
# 'huggingface_SD-XL-v1.0_text2image',
|
10 |
# 'huggingface_IF-I-XL-v1.0_text2image',
|
11 |
# ]
|
12 |
-
|
13 |
-
'imagenhub_SDXL_generation',
|
14 |
-
'imagenhub_OpenJourney_generation',
|
15 |
-
'imagenhub_LCM_generation',
|
16 |
-
'imagenhub_DeepFloydIF_generation',
|
17 |
-
'imagenhub_PixArtAlpha_generation',
|
18 |
-
'imagenhub_Kandinsky_generation',
|
19 |
-
]
|
20 |
# IMAGE_GENERATION_MODELS = [ 'imagenhub_SD_generation',
|
21 |
-
# '
|
22 |
-
# 'imagenhub_SD_generation',
|
23 |
-
# 'imagenhub_SD_generation',
|
24 |
-
# ]
|
25 |
-
# IMAGE_GENERATION_MODELS = ['fal_LCM(v1.5/XL)_text2image',
|
26 |
-
# 'fal_SDXLTurbo_text2image',
|
27 |
-
# 'fal_SDXL_text2image',
|
28 |
-
# 'imagenhub_PixArtAlpha_generation',
|
29 |
-
# 'fal_PixArtSigma_text2image',
|
30 |
# 'imagenhub_OpenJourney_generation',
|
31 |
-
# '
|
32 |
-
# '
|
|
|
|
|
33 |
# ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
IMAGE_EDITION_MODELS = ['imagenhub_CycleDiffusion_edition', 'imagenhub_Pix2PixZero_edition', 'imagenhub_Prompt2prompt_edition',
|
35 |
'imagenhub_SDEdit_edition', 'imagenhub_InstructPix2Pix_edition',
|
36 |
'imagenhub_MagicBrush_edition', 'imagenhub_PNP_edition',
|
@@ -51,16 +67,18 @@ def load_pipeline(model_name):
|
|
51 |
the type is the type of the model, either generation or edition
|
52 |
"""
|
53 |
model_source, model_name, model_type = model_name.split("_")
|
54 |
-
# if model_source == "
|
55 |
-
# pipe =
|
56 |
-
|
57 |
-
|
58 |
-
# elif model_source == "playground":
|
59 |
-
# pipe = load_playground_model(model_name)
|
60 |
-
elif model_source == "fal":
|
61 |
-
pipe = load_fal_model(model_name, model_type)
|
62 |
# elif model_source == "videogenhub":
|
63 |
# pipe = load_videogenhub_model(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
else:
|
65 |
raise ValueError(f"Model source {model_source} not supported")
|
66 |
return pipe
|
|
|
2 |
# from .playground_api import load_playground_model
|
3 |
from .fal_api_models import load_fal_model
|
4 |
# from .videogenhub_models import load_videogenhub_model
|
5 |
+
from .huggingface_models import load_huggingface_model
|
6 |
+
from .replicate_api_models import load_replicate_model
|
7 |
+
from .openai_api_models import load_openai_model
|
8 |
|
9 |
# IMAGE_GENERATION_MODELS = ['huggingface_SD-v1.5_text2image',
|
10 |
# 'huggingface_SD-v2.1_text2image',
|
11 |
# 'huggingface_SD-XL-v1.0_text2image',
|
12 |
# 'huggingface_IF-I-XL-v1.0_text2image',
|
13 |
# ]
|
14 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# IMAGE_GENERATION_MODELS = [ 'imagenhub_SD_generation',
|
16 |
+
# 'imagenhub_SDXL_generation',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# 'imagenhub_OpenJourney_generation',
|
18 |
+
# 'imagenhub_LCM_generation',
|
19 |
+
# 'imagenhub_DeepFloydIF_generation',
|
20 |
+
# 'imagenhub_PixArtAlpha_generation',
|
21 |
+
# 'imagenhub_Kandinsky_generation',
|
22 |
# ]
|
23 |
+
|
24 |
+
IMAGE_GENERATION_MODELS = [
|
25 |
+
'replicate_SDXL_text2image',
|
26 |
+
'replicate_SD-v3.0_text2image',
|
27 |
+
'replicate_SD-v2.1_text2image',
|
28 |
+
'replicate_SD-v1.5_text2image',
|
29 |
+
'replicate_SDXL-Lightning_text2image',
|
30 |
+
'replicate_Kandinsky-v2.0_text2image',
|
31 |
+
'replicate_Kandinsky-v2.2_text2image',
|
32 |
+
'replicate_Proteus-v0.2_text2image',
|
33 |
+
'replicate_Playground-v2.0_text2image',
|
34 |
+
'replicate_Playground-v2.5_text2image',
|
35 |
+
'replicate_Dreamshaper-xl-turbo_text2image',
|
36 |
+
'replicate_SDXL-Deepcache_text2image',
|
37 |
+
'replicate_Openjourney-v4_text2image',
|
38 |
+
'replicate_LCM_text2image',
|
39 |
+
'replicate_Realvisxl-v3.0_text2image',
|
40 |
+
'replicate_Realvisxl-v2.0_text2image',
|
41 |
+
'replicate_Pixart-Sigma_text2image',
|
42 |
+
'replicate_SSD-1b_text2image',
|
43 |
+
'replicate_Open-Dalle-v1.1_text2image',
|
44 |
+
'replicate_Deepfloyd-IF_text2image',
|
45 |
+
'huggingface_SD-turbo_text2image',
|
46 |
+
'huggingface_SDXL-turbo_text2image',
|
47 |
+
]
|
48 |
+
|
49 |
+
|
50 |
IMAGE_EDITION_MODELS = ['imagenhub_CycleDiffusion_edition', 'imagenhub_Pix2PixZero_edition', 'imagenhub_Prompt2prompt_edition',
|
51 |
'imagenhub_SDEdit_edition', 'imagenhub_InstructPix2Pix_edition',
|
52 |
'imagenhub_MagicBrush_edition', 'imagenhub_PNP_edition',
|
|
|
67 |
the type is the type of the model, either generation or edition
|
68 |
"""
|
69 |
model_source, model_name, model_type = model_name.split("_")
|
70 |
+
# if model_source == "imagenhub":
|
71 |
+
# pipe = load_imagenhub_model(model_name, model_type)
|
72 |
+
# elif model_source == "fal":
|
73 |
+
# pipe = load_fal_model(model_name, model_type)
|
|
|
|
|
|
|
|
|
74 |
# elif model_source == "videogenhub":
|
75 |
# pipe = load_videogenhub_model(model_name)
|
76 |
+
if model_source == "replicate":
|
77 |
+
pipe = load_replicate_model(model_name, model_type)
|
78 |
+
elif model_source == "huggingface":
|
79 |
+
pipe = load_huggingface_model(model_name, model_type)
|
80 |
+
elif model_source == "openai":
|
81 |
+
pipe = load_openai_model(model_name)
|
82 |
else:
|
83 |
raise ValueError(f"Model source {model_source} not supported")
|
84 |
return pipe
|
model/models/huggingface_models.py
CHANGED
@@ -1,20 +1,25 @@
|
|
1 |
from diffusers import DiffusionPipeline
|
|
|
2 |
import torch
|
3 |
|
4 |
|
5 |
|
6 |
-
HF_MODEl_ID = {"SD-v1.5": "runwayml/stable-diffusion-v1-5",
|
7 |
-
"SD-v2.1": "runwayml/stable-diffusion-v2-1",
|
8 |
-
"SD-XL-v1.0": "stabilityai/stable-diffusion-xl-base-1.0",
|
9 |
-
"IF-I-XL-v1.0": "DeepFloyd/IF-I-XL-v1.0"}
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
pipe = pipe.to("cuda")
|
16 |
return pipe
|
17 |
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from diffusers import DiffusionPipeline
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
import torch
|
4 |
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def load_huggingface_model(model_name, model_type):
|
9 |
+
if model_name == "SD-turbo":
|
10 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sd-turbo", torch_dtype=torch.float16, variant="fp16")
|
11 |
+
elif model_name == "SDXL-turbo":
|
12 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
13 |
+
else:
|
14 |
+
raise NotImplementedError
|
15 |
pipe = pipe.to("cuda")
|
16 |
return pipe
|
17 |
|
18 |
|
19 |
+
if __name__ == "__main__":
|
20 |
+
for name in ["SD-turbo", "SDXL-turbo"]:
|
21 |
+
load_huggingface_model(name, "text2image")
|
22 |
+
|
23 |
+
# for name in ["IF-I-XL-v1.0"]:
|
24 |
+
# pipe = load_huggingface_model(name, 'text2image')
|
25 |
+
# pipe = DiffusionPipeline.from_pretrained("DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16)
|
model/models/openai_api_models.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
|
3 |
+
|
4 |
+
def load_openai_model(model_name):
|
5 |
+
client = OpenAI()
|
6 |
+
|
7 |
+
if model_name == "Dalle-3":
|
8 |
+
response = client.images.generate(
|
9 |
+
model="dall-e-3",
|
10 |
+
prompt="a white siamese cat",
|
11 |
+
size="1024x1024",
|
12 |
+
quality="standard",
|
13 |
+
n=1,
|
14 |
+
)
|
15 |
+
elif model_name == "Dalle-2":
|
16 |
+
response = client.images.generate(
|
17 |
+
model="dall-e-2",
|
18 |
+
prompt="a white siamese cat",
|
19 |
+
size="512x512",
|
20 |
+
quality="standard",
|
21 |
+
n=1,
|
22 |
+
)
|
23 |
+
else:
|
24 |
+
raise NotImplementedError
|
25 |
+
|
26 |
+
image_url = response.data[0].url
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
load_openai_model('Dalle-2')
|
model/models/replicate_api_models.py
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import replicate
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
import io
|
5 |
+
import os
|
6 |
+
import base64
|
7 |
+
|
8 |
+
Replicate_MODEl_NAME_MAP = {
|
9 |
+
"SDXL": "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
|
10 |
+
"SD-v3.0": "stability-ai/stable-diffusion-3",
|
11 |
+
"SD-v2.1": "stability-ai/stable-diffusion:ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4",
|
12 |
+
"SD-v1.5": "stability-ai/stable-diffusion:b3d14e1cd1f9470bbb0bb68cac48e5f483e5be309551992cc33dc30654a82bb7",
|
13 |
+
"SDXL-Lightning": "bytedance/sdxl-lightning-4step:5f24084160c9089501c1b3545d9be3c27883ae2239b6f412990e82d4a6210f8f",
|
14 |
+
"Kandinsky-v2.0": "ai-forever/kandinsky-2:3c6374e7a9a17e01afe306a5218cc67de55b19ea536466d6ea2602cfecea40a9",
|
15 |
+
"Kandinsky-v2.2": "ai-forever/kandinsky-2.2:ad9d7879fbffa2874e1d909d1d37d9bc682889cc65b31f7bb00d2362619f194a",
|
16 |
+
"Proteus-v0.2": "lucataco/proteus-v0.2:06775cd262843edbde5abab958abdbb65a0a6b58ca301c9fd78fa55c775fc019",
|
17 |
+
"Playground-v2.0": "playgroundai/playground-v2-1024px-aesthetic:42fe626e41cc811eaf02c94b892774839268ce1994ea778eba97103fe1ef51b8",
|
18 |
+
"Playground-v2.5": "playgroundai/playground-v2.5-1024px-aesthetic:a45f82a1382bed5c7aeb861dac7c7d191b0fdf74d8d57c4a0e6ed7d4d0bf7d24",
|
19 |
+
"Dreamshaper-xl-turbo": "lucataco/dreamshaper-xl-turbo:0a1710e0187b01a255302738ca0158ff02a22f4638679533e111082f9dd1b615",
|
20 |
+
"SDXL-Deepcache": "lucataco/sdxl-deepcache:eaf678fb34006669e9a3c6dd5971e2279bf20ee0adeced464d7b6d95de16dc93",
|
21 |
+
"Openjourney-v4": "prompthero/openjourney:ad59ca21177f9e217b9075e7300cf6e14f7e5b4505b87b9689dbd866e9768969",
|
22 |
+
"LCM": "fofr/latent-consistency-model:683d19dc312f7a9f0428b04429a9ccefd28dbf7785fef083ad5cf991b65f406f",
|
23 |
+
"Realvisxl-v3.0": "fofr/realvisxl-v3:33279060bbbb8858700eb2146350a98d96ef334fcf817f37eb05915e1534aa1c",
|
24 |
+
|
25 |
+
"Realvisxl-v2.0": "lucataco/realvisxl-v2.0:7d6a2f9c4754477b12c14ed2a58f89bb85128edcdd581d24ce58b6926029de08",
|
26 |
+
"Pixart-Sigma": "cjwbw/pixart-sigma:5a54352c99d9fef467986bc8f3a20205e8712cbd3df1cbae4975d6254c902de1",
|
27 |
+
"SSD-1b": "lucataco/ssd-1b:b19e3639452c59ce8295b82aba70a231404cb062f2eb580ea894b31e8ce5bbb6",
|
28 |
+
"Open-Dalle-v1.1": "lucataco/open-dalle-v1.1:1c7d4c8dec39c7306df7794b28419078cb9d18b9213ab1c21fdc46a1deca0144",
|
29 |
+
"Deepfloyd-IF": "andreasjansson/deepfloyd-if:fb84d659df149f4515c351e394d22222a94144aa1403870c36025c8b28846c8d",
|
30 |
+
}
|
31 |
+
|
32 |
+
class ReplicateModel():
|
33 |
+
def __init__(self, model_name, model_type):
|
34 |
+
self.model_name = model_name
|
35 |
+
self.model_type = model_type
|
36 |
+
# os.environ['FAL_KEY'] = os.environ['FalAPI']
|
37 |
+
|
38 |
+
def __call__(self, *args, **kwargs):
|
39 |
+
# def decode_data_url(data_url):
|
40 |
+
# # Find the start of the Base64 encoded data
|
41 |
+
# base64_start = data_url.find(",") + 1
|
42 |
+
# if base64_start == 0:
|
43 |
+
# raise ValueError("Invalid data URL provided")
|
44 |
+
|
45 |
+
# # Extract the Base64 encoded data
|
46 |
+
# base64_string = data_url[base64_start:]
|
47 |
+
|
48 |
+
# # Decode the Base64 string
|
49 |
+
# decoded_bytes = base64.b64decode(base64_string)
|
50 |
+
|
51 |
+
# return decoded_bytes
|
52 |
+
|
53 |
+
if self.model_type == "text2image":
|
54 |
+
assert "prompt" in kwargs, "prompt is required for text2image model"
|
55 |
+
output = replicate.run(
|
56 |
+
f"{Replicate_MODEl_NAME_MAP[self.model_name]}",
|
57 |
+
input={
|
58 |
+
"width": 512,
|
59 |
+
"height": 512,
|
60 |
+
"prompt": kwargs["prompt"]
|
61 |
+
},
|
62 |
+
)
|
63 |
+
if 'Openjourney' in self.model_name:
|
64 |
+
for item in output:
|
65 |
+
result_url = item
|
66 |
+
break
|
67 |
+
elif isinstance(output, list):
|
68 |
+
result_url = output[0]
|
69 |
+
else:
|
70 |
+
result_url = output
|
71 |
+
print(result_url)
|
72 |
+
response = requests.get(result_url)
|
73 |
+
result = Image.open(io.BytesIO(response.content))
|
74 |
+
# fal_client.submit(
|
75 |
+
# f"fal-ai/{FAL_MODEl_NAME_MAP[self.model_name]}",
|
76 |
+
# arguments={
|
77 |
+
# "prompt": kwargs["prompt"]
|
78 |
+
# },
|
79 |
+
# )
|
80 |
+
# for event in handler.iter_events(with_logs=True):
|
81 |
+
# if isinstance(event, fal_client.InProgress):
|
82 |
+
# print('Request in progress')
|
83 |
+
# print(event.logs)
|
84 |
+
# result = handler.get()
|
85 |
+
# print(result)
|
86 |
+
# result_url = result['images'][0]['url']
|
87 |
+
# if self.model_name in ["SDXLTurbo", "LCM(v1.5/XL)"]:
|
88 |
+
# result_url = io.BytesIO(decode_data_url(result_url))
|
89 |
+
# result = Image.open(result_url)
|
90 |
+
# else:
|
91 |
+
# response = requests.get(result_url)
|
92 |
+
# result = Image.open(io.BytesIO(response.content))
|
93 |
+
return result
|
94 |
+
# elif self.model_type == "image2image":
|
95 |
+
# raise NotImplementedError("image2image model is not implemented yet")
|
96 |
+
# # assert "image" in kwargs or "image_url" in kwargs, "image or image_url is required for image2image model"
|
97 |
+
# # if "image" in kwargs:
|
98 |
+
# # image_url = None
|
99 |
+
# # pass
|
100 |
+
# # handler = fal_client.submit(
|
101 |
+
# # f"fal-ai/{self.model_name}",
|
102 |
+
# # arguments={
|
103 |
+
# # "image_url": image_url
|
104 |
+
# # },
|
105 |
+
# # )
|
106 |
+
# #
|
107 |
+
# # for event in handler.iter_events():
|
108 |
+
# # if isinstance(event, fal_client.InProgress):
|
109 |
+
# # print('Request in progress')
|
110 |
+
# # print(event.logs)
|
111 |
+
# #
|
112 |
+
# # result = handler.get()
|
113 |
+
# # return result
|
114 |
+
# elif self.model_type == "text2video":
|
115 |
+
# assert "prompt" in kwargs, "prompt is required for text2video model"
|
116 |
+
# if self.model_name == 'AnimateDiff':
|
117 |
+
# fal_model_name = 'fast-animatediff/text-to-video'
|
118 |
+
# elif self.model_name == 'AnimateDiffTurbo':
|
119 |
+
# fal_model_name = 'fast-animatediff/turbo/text-to-video'
|
120 |
+
# else:
|
121 |
+
# raise NotImplementedError(f"text2video model of {self.model_name} in fal is not implemented yet")
|
122 |
+
# handler = fal_client.submit(
|
123 |
+
# f"fal-ai/{fal_model_name}",
|
124 |
+
# arguments={
|
125 |
+
# "prompt": kwargs["prompt"]
|
126 |
+
# },
|
127 |
+
# )
|
128 |
+
|
129 |
+
# for event in handler.iter_events(with_logs=True):
|
130 |
+
# if isinstance(event, fal_client.InProgress):
|
131 |
+
# print('Request in progress')
|
132 |
+
# print(event.logs)
|
133 |
+
|
134 |
+
# result = handler.get()
|
135 |
+
# print("result video: ====")
|
136 |
+
# print(result)
|
137 |
+
# result_url = result['video']['url']
|
138 |
+
# return result_url
|
139 |
+
else:
|
140 |
+
raise ValueError("model_type must be text2image or image2image")
|
141 |
+
|
142 |
+
def load_replicate_model(model_name, model_type):
|
143 |
+
return ReplicateModel(model_name, model_type)
|
144 |
+
|
145 |
+
|
146 |
+
if __name__ == "__main__":
|
147 |
+
import replicate
|
148 |
+
import time
|
149 |
+
input = {
|
150 |
+
"seed": 1,
|
151 |
+
"width": 512,
|
152 |
+
"height": 512,
|
153 |
+
"grid_size": 1,
|
154 |
+
"prompt": "anime astronaut riding a horse on mars"
|
155 |
+
}
|
156 |
+
|
157 |
+
|
158 |
+
for name, address in Replicate_MODEl_NAME_MAP.items():
|
159 |
+
print('*'*50)
|
160 |
+
print(name)
|
161 |
+
|
162 |
+
t1 = time.time()
|
163 |
+
output = replicate.run(
|
164 |
+
address,
|
165 |
+
input=input
|
166 |
+
)
|
167 |
+
# for item in output:
|
168 |
+
# print(item)
|
169 |
+
print(output)
|
170 |
+
|
171 |
+
|
172 |
+
t2 = time.time()
|
173 |
+
print(t2-t1)
|
174 |
+
print('*'*50)
|
175 |
+
|
requirements.txt
CHANGED
@@ -69,3 +69,4 @@ timm
|
|
69 |
pandarallel
|
70 |
wandb
|
71 |
trueskill
|
|
|
|
69 |
pandarallel
|
70 |
wandb
|
71 |
trueskill
|
72 |
+
replicate
|
serve/Ksort.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
3 |
import os
|
4 |
from .constants import KSORT_IMAGE_DIR
|
|
|
5 |
from .vote_utils import save_any_image
|
6 |
from .utils import disable_btn, enable_btn, invisible_btn
|
7 |
from .upload import create_remote_directory, upload_image, upload_informance, upload_ssh_all
|
@@ -103,19 +104,20 @@ def reset_submit(rank):
|
|
103 |
def reset_mode(mode):
|
104 |
|
105 |
if mode == "Best":
|
106 |
-
return (gr.update(visible=False, interactive=False),) *
|
107 |
(gr.update(visible=True, interactive=True),) * 16 + \
|
108 |
(gr.update(visible=True, interactive=True),) * 3 + \
|
109 |
(gr.Textbox(value="Rank", visible=False, interactive=False),)
|
110 |
elif mode == "Rank":
|
111 |
-
return (gr.update(visible=True, interactive=True),) *
|
112 |
(gr.update(visible=False, interactive=False),) * 16 + \
|
113 |
(gr.update(visible=True, interactive=False),) * 2 + \
|
114 |
(gr.update(visible=True, interactive=True),) + \
|
115 |
(gr.Textbox(value="Best", visible=False, interactive=False),)
|
116 |
else:
|
117 |
raise ValueError("Undefined mode")
|
118 |
-
|
|
|
119 |
def get_json_filename(conv_id):
|
120 |
output_dir = f'{KSORT_IMAGE_DIR}/{conv_id}/json/'
|
121 |
if not os.path.exists(output_dir):
|
@@ -155,12 +157,12 @@ def vote_ssh_submit(states, rank):
|
|
155 |
"models_name": [x.model_name for x in states],
|
156 |
"img_rank": [x for x in rank],
|
157 |
}
|
158 |
-
output_file = os.path.join(output_dir, "
|
159 |
# upload_informance(data, output_file)
|
160 |
upload_ssh_all(states, output_dir, data, output_file)
|
161 |
|
162 |
from .update_skill import update_skill
|
163 |
-
update_skill(rank)
|
164 |
|
165 |
|
166 |
def submit_response_igm(
|
@@ -169,14 +171,14 @@ def submit_response_igm(
|
|
169 |
vote_submit([state0, state1, state2, state3], rank, request)
|
170 |
vote_ssh_submit([state0, state1, state2, state3], rank)
|
171 |
if model_selector0 == "":
|
172 |
-
return (disable_btn,) *
|
173 |
gr.Markdown(f"### Model A: {state0.model_name.split('_')[1]}", visible=True),
|
174 |
gr.Markdown(f"### Model B: {state1.model_name.split('_')[1]}", visible=True),
|
175 |
gr.Markdown(f"### Model C: {state2.model_name.split('_')[1]}", visible=True),
|
176 |
gr.Markdown(f"### Model D: {state3.model_name.split('_')[1]}", visible=True)
|
177 |
) + (disable_btn,)
|
178 |
else:
|
179 |
-
return (disable_btn,) *
|
180 |
gr.Markdown(state0.model_name, visible=True),
|
181 |
gr.Markdown(state1.model_name, visible=True),
|
182 |
gr.Markdown(state2.model_name, visible=True),
|
@@ -217,63 +219,35 @@ def text_response_rank_igm(generate_ig0, generate_ig1, generate_ig2, generate_ig
|
|
217 |
for num in range(len(rank_list)):
|
218 |
if rank_list[num] in ['1', '2', '3', '4']:
|
219 |
base_image = Image.fromarray(generate_ig[num]).convert("RGBA")
|
|
|
220 |
if rank_list[num] == '1':
|
221 |
-
border_color =
|
222 |
elif rank_list[num] == '2':
|
223 |
-
border_color =
|
224 |
elif rank_list[num] == '3':
|
225 |
-
border_color =
|
226 |
elif rank_list[num] == '4':
|
227 |
-
border_color =
|
228 |
border_size = 10 # Size of the border
|
229 |
base_image = ImageOps.expand(base_image, border=border_size, fill=border_color)
|
230 |
|
231 |
draw = ImageDraw.Draw(base_image)
|
232 |
-
font = ImageFont.truetype("./serve/Arial.ttf",
|
233 |
-
text_position = (
|
234 |
if rank_list[num] == '1':
|
235 |
-
text_color =
|
236 |
draw.text(text_position, Top1_text, font=font, fill=text_color)
|
237 |
elif rank_list[num] == '2':
|
238 |
-
text_color =
|
239 |
draw.text(text_position, Top2_text, font=font, fill=text_color)
|
240 |
elif rank_list[num] == '3':
|
241 |
-
text_color =
|
242 |
draw.text(text_position, Top3_text, font=font, fill=text_color)
|
243 |
elif rank_list[num] == '4':
|
244 |
-
text_color =
|
245 |
draw.text(text_position, Top4_text, font=font, fill=text_color)
|
246 |
base_image = base_image.convert("RGB")
|
247 |
chatbot.append(base_image.copy())
|
248 |
-
|
249 |
-
# base_image = Image.fromarray(generate_ig[num]).convert("RGBA")
|
250 |
-
# if rank_list[num] == '1':
|
251 |
-
# txt_layer = Image.new('RGBA', base_image.size, (0, 255, 0, 64))
|
252 |
-
# elif rank_list[num] == '2':
|
253 |
-
# txt_layer = Image.new('RGBA', base_image.size, (0, 255, 255, 64))
|
254 |
-
# elif rank_list[num] == '3':
|
255 |
-
# txt_layer = Image.new('RGBA', base_image.size, (255, 0, 255, 64))
|
256 |
-
# elif rank_list[num] == '4':
|
257 |
-
# txt_layer = Image.new('RGBA', base_image.size, (255, 0, 0, 64))
|
258 |
-
# draw = ImageDraw.Draw(txt_layer)
|
259 |
-
# font = ImageFont.truetype("./serve/Arial.ttf", 86)
|
260 |
-
# text_position = (156, 212)
|
261 |
-
# if rank_list[num] == '1':
|
262 |
-
# text_color = (0, 255, 0, 200)
|
263 |
-
# draw.text(text_position, Top1_text, font=font, fill=text_color)
|
264 |
-
# elif rank_list[num] == '2':
|
265 |
-
# text_color = (0, 255, 255, 200)
|
266 |
-
# draw.text(text_position, Top2_text, font=font, fill=text_color)
|
267 |
-
# elif rank_list[num] == '3':
|
268 |
-
# text_color = (255, 0, 255, 200)
|
269 |
-
# draw.text(text_position, Top3_text, font=font, fill=text_color)
|
270 |
-
# elif rank_list[num] == '4':
|
271 |
-
# text_color = (255, 0, 0, 200)
|
272 |
-
# draw.text(text_position, Top4_text, font=font, fill=text_color)
|
273 |
-
|
274 |
-
# combined = Image.alpha_composite(base_image, txt_layer)
|
275 |
-
# combined = combined.convert("RGB")
|
276 |
-
# chatbot.append(combined.copy())
|
277 |
else:
|
278 |
return generate_ig + ["error rank"] + ["wrong"] + [rank]
|
279 |
rank_str = ""
|
@@ -317,35 +291,35 @@ def text_response_rank_igm(generate_ig0, generate_ig1, generate_ig2, generate_ig
|
|
317 |
# return combined
|
318 |
def add_foreground(image, vote_level, Top1_text, Top2_text, Top3_text, Top4_text):
|
319 |
base_image = Image.fromarray(image).convert("RGBA")
|
|
|
320 |
if vote_level == 0:
|
321 |
-
border_color =
|
322 |
elif vote_level == 1:
|
323 |
-
border_color =
|
324 |
elif vote_level == 2:
|
325 |
-
border_color =
|
326 |
elif vote_level == 3:
|
327 |
-
border_color =
|
328 |
border_size = 10 # Size of the border
|
329 |
base_image = ImageOps.expand(base_image, border=border_size, fill=border_color)
|
330 |
|
331 |
draw = ImageDraw.Draw(base_image)
|
332 |
-
font = ImageFont.truetype("./serve/Arial.ttf",
|
333 |
|
334 |
-
text_position = (
|
335 |
if vote_level == 0:
|
336 |
-
text_color =
|
337 |
draw.text(text_position, Top1_text, font=font, fill=text_color)
|
338 |
elif vote_level == 1:
|
339 |
-
text_color =
|
340 |
draw.text(text_position, Top2_text, font=font, fill=text_color)
|
341 |
elif vote_level == 2:
|
342 |
-
text_color =
|
343 |
draw.text(text_position, Top3_text, font=font, fill=text_color)
|
344 |
elif vote_level == 3:
|
345 |
-
text_color =
|
346 |
draw.text(text_position, Top4_text, font=font, fill=text_color)
|
347 |
|
348 |
-
# combined = Image.alpha_composite(base_image, txt_layer)
|
349 |
base_image = base_image.convert("RGB")
|
350 |
return base_image
|
351 |
def add_green_border(image):
|
|
|
2 |
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
3 |
import os
|
4 |
from .constants import KSORT_IMAGE_DIR
|
5 |
+
from .constants import COLOR1, COLOR2, COLOR3, COLOR4
|
6 |
from .vote_utils import save_any_image
|
7 |
from .utils import disable_btn, enable_btn, invisible_btn
|
8 |
from .upload import create_remote_directory, upload_image, upload_informance, upload_ssh_all
|
|
|
104 |
def reset_mode(mode):
|
105 |
|
106 |
if mode == "Best":
|
107 |
+
return (gr.update(visible=False, interactive=False),) * 5 + \
|
108 |
(gr.update(visible=True, interactive=True),) * 16 + \
|
109 |
(gr.update(visible=True, interactive=True),) * 3 + \
|
110 |
(gr.Textbox(value="Rank", visible=False, interactive=False),)
|
111 |
elif mode == "Rank":
|
112 |
+
return (gr.update(visible=True, interactive=True),) * 5 + \
|
113 |
(gr.update(visible=False, interactive=False),) * 16 + \
|
114 |
(gr.update(visible=True, interactive=False),) * 2 + \
|
115 |
(gr.update(visible=True, interactive=True),) + \
|
116 |
(gr.Textbox(value="Best", visible=False, interactive=False),)
|
117 |
else:
|
118 |
raise ValueError("Undefined mode")
|
119 |
+
def reset_chatbot(mode, generate_ig0, generate_ig1, generate_ig2, generate_ig3):
|
120 |
+
return generate_ig0, generate_ig1, generate_ig2, generate_ig3
|
121 |
def get_json_filename(conv_id):
|
122 |
output_dir = f'{KSORT_IMAGE_DIR}/{conv_id}/json/'
|
123 |
if not os.path.exists(output_dir):
|
|
|
157 |
"models_name": [x.model_name for x in states],
|
158 |
"img_rank": [x for x in rank],
|
159 |
}
|
160 |
+
output_file = os.path.join(output_dir, "result.json")
|
161 |
# upload_informance(data, output_file)
|
162 |
upload_ssh_all(states, output_dir, data, output_file)
|
163 |
|
164 |
from .update_skill import update_skill
|
165 |
+
update_skill(rank, [x.model_name for x in states])
|
166 |
|
167 |
|
168 |
def submit_response_igm(
|
|
|
171 |
vote_submit([state0, state1, state2, state3], rank, request)
|
172 |
vote_ssh_submit([state0, state1, state2, state3], rank)
|
173 |
if model_selector0 == "":
|
174 |
+
return (disable_btn,) * 6 + (
|
175 |
gr.Markdown(f"### Model A: {state0.model_name.split('_')[1]}", visible=True),
|
176 |
gr.Markdown(f"### Model B: {state1.model_name.split('_')[1]}", visible=True),
|
177 |
gr.Markdown(f"### Model C: {state2.model_name.split('_')[1]}", visible=True),
|
178 |
gr.Markdown(f"### Model D: {state3.model_name.split('_')[1]}", visible=True)
|
179 |
) + (disable_btn,)
|
180 |
else:
|
181 |
+
return (disable_btn,) * 6 + (
|
182 |
gr.Markdown(state0.model_name, visible=True),
|
183 |
gr.Markdown(state1.model_name, visible=True),
|
184 |
gr.Markdown(state2.model_name, visible=True),
|
|
|
219 |
for num in range(len(rank_list)):
|
220 |
if rank_list[num] in ['1', '2', '3', '4']:
|
221 |
base_image = Image.fromarray(generate_ig[num]).convert("RGBA")
|
222 |
+
base_image = base_image.resize((512, 512), Image.ANTIALIAS)
|
223 |
if rank_list[num] == '1':
|
224 |
+
border_color = COLOR1
|
225 |
elif rank_list[num] == '2':
|
226 |
+
border_color = COLOR2
|
227 |
elif rank_list[num] == '3':
|
228 |
+
border_color = COLOR3
|
229 |
elif rank_list[num] == '4':
|
230 |
+
border_color = COLOR4
|
231 |
border_size = 10 # Size of the border
|
232 |
base_image = ImageOps.expand(base_image, border=border_size, fill=border_color)
|
233 |
|
234 |
draw = ImageDraw.Draw(base_image)
|
235 |
+
font = ImageFont.truetype("./serve/Arial.ttf", 66)
|
236 |
+
text_position = (180, 25)
|
237 |
if rank_list[num] == '1':
|
238 |
+
text_color = COLOR1
|
239 |
draw.text(text_position, Top1_text, font=font, fill=text_color)
|
240 |
elif rank_list[num] == '2':
|
241 |
+
text_color = COLOR2
|
242 |
draw.text(text_position, Top2_text, font=font, fill=text_color)
|
243 |
elif rank_list[num] == '3':
|
244 |
+
text_color = COLOR3
|
245 |
draw.text(text_position, Top3_text, font=font, fill=text_color)
|
246 |
elif rank_list[num] == '4':
|
247 |
+
text_color = COLOR4
|
248 |
draw.text(text_position, Top4_text, font=font, fill=text_color)
|
249 |
base_image = base_image.convert("RGB")
|
250 |
chatbot.append(base_image.copy())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
else:
|
252 |
return generate_ig + ["error rank"] + ["wrong"] + [rank]
|
253 |
rank_str = ""
|
|
|
291 |
# return combined
|
292 |
def add_foreground(image, vote_level, Top1_text, Top2_text, Top3_text, Top4_text):
|
293 |
base_image = Image.fromarray(image).convert("RGBA")
|
294 |
+
base_image = base_image.resize((512, 512), Image.ANTIALIAS)
|
295 |
if vote_level == 0:
|
296 |
+
border_color = COLOR1
|
297 |
elif vote_level == 1:
|
298 |
+
border_color = COLOR2
|
299 |
elif vote_level == 2:
|
300 |
+
border_color = COLOR3
|
301 |
elif vote_level == 3:
|
302 |
+
border_color = COLOR4
|
303 |
border_size = 10 # Size of the border
|
304 |
base_image = ImageOps.expand(base_image, border=border_size, fill=border_color)
|
305 |
|
306 |
draw = ImageDraw.Draw(base_image)
|
307 |
+
font = ImageFont.truetype("./serve/Arial.ttf", 66)
|
308 |
|
309 |
+
text_position = (180, 25)
|
310 |
if vote_level == 0:
|
311 |
+
text_color = COLOR1
|
312 |
draw.text(text_position, Top1_text, font=font, fill=text_color)
|
313 |
elif vote_level == 1:
|
314 |
+
text_color = COLOR2
|
315 |
draw.text(text_position, Top2_text, font=font, fill=text_color)
|
316 |
elif vote_level == 2:
|
317 |
+
text_color = COLOR3
|
318 |
draw.text(text_position, Top3_text, font=font, fill=text_color)
|
319 |
elif vote_level == 3:
|
320 |
+
text_color = COLOR4
|
321 |
draw.text(text_position, Top4_text, font=font, fill=text_color)
|
322 |
|
|
|
323 |
base_image = base_image.convert("RGB")
|
324 |
return base_image
|
325 |
def add_green_border(image):
|
serve/gradio_web.py
CHANGED
@@ -28,10 +28,12 @@ from .Ksort import (
|
|
28 |
reset_submit,
|
29 |
clear_rank,
|
30 |
reset_mode,
|
|
|
31 |
reset_btn_rank,
|
32 |
reset_vote_text,
|
33 |
text_response_rank_igm,
|
34 |
)
|
|
|
35 |
from functools import partial
|
36 |
|
37 |
def build_side_by_side_ui_anony(models):
|
@@ -88,41 +90,28 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
88 |
with gr.Row():
|
89 |
slow_warning = gr.Markdown("", elem_id="notice_markdown")
|
90 |
|
91 |
-
with gr.Row():
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
)
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
with gr.Row():
|
110 |
-
Top1_btn = gr.Button(
|
111 |
-
value="Top1", visible=False, interactive=False
|
112 |
-
)
|
113 |
-
Top2_btn = gr.Button(
|
114 |
-
value="Top2", visible=False, interactive=False
|
115 |
-
)
|
116 |
-
Top3_btn = gr.Button(
|
117 |
-
value="Top3", visible=False, interactive=False
|
118 |
-
)
|
119 |
-
Top4_btn = gr.Button(
|
120 |
-
value="Top4", visible=False, interactive=False
|
121 |
-
)
|
122 |
-
Revote_btn = gr.Button(
|
123 |
-
value="Re-vote", visible=False, interactive=False
|
124 |
-
)
|
125 |
-
Submit_btn = gr.Button(value="🤝 Submit", visible=False, interactive=False)
|
126 |
with gr.Row():
|
127 |
with gr.Blocks():
|
128 |
with gr.Row():
|
@@ -205,8 +194,8 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
205 |
elem_id="input_box",
|
206 |
visible=False,
|
207 |
)
|
208 |
-
vote_submit_btn = gr.Button(value="Submit", visible=False, interactive=False, variant="primary", scale=0)
|
209 |
-
vote_mode_btn = gr.Button(value="🔄 Mode", visible=False, interactive=False, variant="primary", scale=0)
|
210 |
|
211 |
with gr.Row():
|
212 |
textbox = gr.Textbox(
|
@@ -215,28 +204,28 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
215 |
container=True,
|
216 |
elem_id="input_box",
|
217 |
)
|
|
|
|
|
218 |
send_btn = gr.Button(value="Send", variant="primary", scale=0)
|
219 |
-
draw_btn = gr.Button(value="🎲 Random
|
220 |
-
|
221 |
with gr.Row():
|
222 |
clear_btn = gr.Button(value="🎲 New Round", interactive=False)
|
223 |
-
regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False)
|
224 |
# share_btn = gr.Button(value="📷 Share")
|
225 |
|
226 |
#gr.Markdown(acknowledgment_md, elem_id="ack_markdown")
|
227 |
|
228 |
dummy_img_output = gr.Image(width=512, visible=False)
|
229 |
gr.Examples(
|
230 |
-
examples=[["a
|
231 |
-
["
|
232 |
-
["
|
233 |
-
["
|
234 |
inputs = [textbox, dummy_img_output])
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
vote_order_list = [leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, bothbad_btn, \
|
240 |
A1_btn, A2_btn, A3_btn, A4_btn, B1_btn, B2_btn, B3_btn, B4_btn, C1_btn, C2_btn, C3_btn, C4_btn, D1_btn, D2_btn, D3_btn, D4_btn, \
|
241 |
vote_textbox, vote_submit_btn, vote_mode_btn]
|
242 |
# vote_rank_list = [A1_btn, A2_btn, A3_btn, A4_btn, B1_btn, B2_btn, B3_btn, B4_btn, C1_btn, C2_btn, C3_btn, C4_btn, D1_btn, D2_btn, D3_btn, D4_btn]
|
@@ -273,10 +262,10 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
273 |
window3_text = gr.Textbox(value="Model C", visible=False, interactive=False)
|
274 |
window4_text = gr.Textbox(value="Model D", visible=False, interactive=False)
|
275 |
vote_level = gr.Number(value=0, visible=False, interactive=False)
|
276 |
-
Top1_btn.click(reset_level, inputs=[Top1_text], outputs=[vote_level])
|
277 |
-
Top2_btn.click(reset_level, inputs=[Top2_text], outputs=[vote_level])
|
278 |
-
Top3_btn.click(reset_level, inputs=[Top3_text], outputs=[vote_level])
|
279 |
-
Top4_btn.click(reset_level, inputs=[Top4_text], outputs=[vote_level])
|
280 |
vote_mode = gr.Textbox(value="Best", visible=False, interactive=False)
|
281 |
right_vote_text = gr.Textbox(value="wrong", visible=False, interactive=False)
|
282 |
|
@@ -312,26 +301,27 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
312 |
outputs=vote_order_list
|
313 |
)
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
draw_btn.click(
|
316 |
-
|
317 |
-
inputs=
|
318 |
-
outputs=[
|
319 |
-
textbox, model_selector_left, model_selector_left1, model_selector_right, model_selector_right1],
|
320 |
api_name="draw_btn_annony"
|
321 |
-
).then(
|
322 |
-
disable_order_buttons,
|
323 |
-
inputs=None,
|
324 |
-
outputs=order_btn_list
|
325 |
-
).then(
|
326 |
-
enable_vote_mode_buttons,
|
327 |
-
inputs=[vote_mode],
|
328 |
-
outputs=vote_order_list
|
329 |
)
|
330 |
-
# .then(
|
331 |
-
# enable_vote_buttons,
|
332 |
-
# inputs=None,
|
333 |
-
# outputs=vote_list
|
334 |
-
# )
|
335 |
|
336 |
clear_btn.click(
|
337 |
clear_history_side_by_side_anony,
|
@@ -343,10 +333,6 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
343 |
enable_order_buttons,
|
344 |
inputs=None,
|
345 |
outputs=order_btn_list
|
346 |
-
).then(
|
347 |
-
disable_vote_buttons,
|
348 |
-
inputs=None,
|
349 |
-
outputs=vote_list
|
350 |
).then(
|
351 |
clear_rank,
|
352 |
inputs=[rank, vote_level],
|
@@ -369,16 +355,25 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
369 |
# outputs=btn_list
|
370 |
# )
|
371 |
vote_mode_btn.click(
|
|
|
|
|
|
|
|
|
372 |
reset_mode,
|
373 |
inputs=[vote_mode],
|
374 |
-
outputs=[leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn,
|
375 |
A1_btn, A2_btn, A3_btn, A4_btn, B1_btn, B2_btn, B3_btn, B4_btn, C1_btn, C2_btn, C3_btn, C4_btn, D1_btn, D2_btn, D3_btn, D4_btn, \
|
376 |
vote_textbox, vote_submit_btn, vote_mode_btn, vote_mode]
|
377 |
-
)
|
|
|
378 |
vote_textbox.submit(
|
379 |
text_response_rank_igm,
|
380 |
inputs=[generate_ig0, generate_ig1, generate_ig2, generate_ig3, Top1_text, Top2_text, Top3_text, Top4_text, vote_textbox],
|
381 |
outputs=[chatbot_left, chatbot_left1, chatbot_right, chatbot_right1, vote_textbox, right_vote_text, rank]
|
|
|
|
|
|
|
|
|
382 |
).then(
|
383 |
submit_response_rank_igm,
|
384 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rank, right_vote_text],
|
@@ -391,6 +386,10 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
391 |
text_response_rank_igm,
|
392 |
inputs=[generate_ig0, generate_ig1, generate_ig2, generate_ig3, Top1_text, Top2_text, Top3_text, Top4_text, vote_textbox],
|
393 |
outputs=[chatbot_left, chatbot_left1, chatbot_right, chatbot_right1, vote_textbox, right_vote_text, rank]
|
|
|
|
|
|
|
|
|
394 |
).then(
|
395 |
submit_response_rank_igm,
|
396 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rank, right_vote_text],
|
@@ -457,42 +456,35 @@ Find out who is the 🥇conditional image generation models! More models are goi
|
|
457 |
leftvote_btn.click(
|
458 |
submit_response_igm,
|
459 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankA],
|
460 |
-
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn,
|
461 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
462 |
vote_mode_btn]
|
463 |
)
|
464 |
left1vote_btn.click(
|
465 |
submit_response_igm,
|
466 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankB],
|
467 |
-
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn,
|
468 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
469 |
vote_mode_btn]
|
470 |
)
|
471 |
rightvote_btn.click(
|
472 |
submit_response_igm,
|
473 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankC],
|
474 |
-
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn,
|
475 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
476 |
vote_mode_btn]
|
477 |
)
|
478 |
right1vote_btn.click(
|
479 |
submit_response_igm,
|
480 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankD],
|
481 |
-
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn,
|
482 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
483 |
vote_mode_btn]
|
484 |
)
|
485 |
tie_btn.click(
|
486 |
submit_response_igm,
|
487 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankTie],
|
488 |
-
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn,
|
489 |
-
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
490 |
-
vote_mode_btn]
|
491 |
-
)
|
492 |
-
bothbad_btn.click(
|
493 |
-
submit_response_igm,
|
494 |
-
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankBad],
|
495 |
-
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, bothbad_btn, \
|
496 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
497 |
vote_mode_btn]
|
498 |
)
|
|
|
28 |
reset_submit,
|
29 |
clear_rank,
|
30 |
reset_mode,
|
31 |
+
reset_chatbot,
|
32 |
reset_btn_rank,
|
33 |
reset_vote_text,
|
34 |
text_response_rank_igm,
|
35 |
)
|
36 |
+
from serve.upload import get_random_mscoco_prompt
|
37 |
from functools import partial
|
38 |
|
39 |
def build_side_by_side_ui_anony(models):
|
|
|
90 |
with gr.Row():
|
91 |
slow_warning = gr.Markdown("", elem_id="notice_markdown")
|
92 |
|
93 |
+
with gr.Row(elem_classes="row"):
|
94 |
+
with gr.Column(scale=1, min_width=10):
|
95 |
+
leftvote_btn = gr.Button(
|
96 |
+
value="A is Best", visible=False, interactive=False, elem_id="btncolor1", elem_classes="best-button"
|
97 |
+
)
|
98 |
+
with gr.Column(scale=1, min_width=10):
|
99 |
+
left1vote_btn = gr.Button(
|
100 |
+
value="B is Best", visible=False, interactive=False, elem_id="btncolor1", elem_classes="best-button"
|
101 |
+
)
|
102 |
+
with gr.Column(scale=1, min_width=10):
|
103 |
+
rightvote_btn = gr.Button(
|
104 |
+
value="C is Best", visible=False, interactive=False, elem_id="btncolor1", elem_classes="best-button"
|
105 |
+
)
|
106 |
+
with gr.Column(scale=1, min_width=10):
|
107 |
+
right1vote_btn = gr.Button(
|
108 |
+
value="D is Best", visible=False, interactive=False, elem_id="btncolor1", elem_classes="best-button"
|
109 |
+
)
|
110 |
+
with gr.Column(scale=1, min_width=10):
|
111 |
+
tie_btn = gr.Button(
|
112 |
+
value="🤝 Tie", visible=False, interactive=False, elem_id="btncolor2", elem_classes="best-button"
|
113 |
+
)
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
with gr.Row():
|
116 |
with gr.Blocks():
|
117 |
with gr.Row():
|
|
|
194 |
elem_id="input_box",
|
195 |
visible=False,
|
196 |
)
|
197 |
+
vote_submit_btn = gr.Button(value="Submit", visible=False, interactive=False, variant="primary", scale=0, elem_id="btnpink", elem_classes="submit-button")
|
198 |
+
vote_mode_btn = gr.Button(value="🔄 Mode", visible=False, interactive=False, variant="primary", scale=0, elem_id="btnpink", elem_classes="submit-button")
|
199 |
|
200 |
with gr.Row():
|
201 |
textbox = gr.Textbox(
|
|
|
204 |
container=True,
|
205 |
elem_id="input_box",
|
206 |
)
|
207 |
+
# send_btn = gr.Button(value="Send", variant="primary", scale=0, elem_id="btnblue", elem_classes="send-button")
|
208 |
+
# draw_btn = gr.Button(value="🎲 Random sample", variant="primary", scale=0, elem_id="btnblue", elem_classes="send-button")
|
209 |
send_btn = gr.Button(value="Send", variant="primary", scale=0)
|
210 |
+
draw_btn = gr.Button(value="🎲 Random Prompt", variant="primary", scale=0)
|
|
|
211 |
with gr.Row():
|
212 |
clear_btn = gr.Button(value="🎲 New Round", interactive=False)
|
213 |
+
# regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False)
|
214 |
# share_btn = gr.Button(value="📷 Share")
|
215 |
|
216 |
#gr.Markdown(acknowledgment_md, elem_id="ack_markdown")
|
217 |
|
218 |
dummy_img_output = gr.Image(width=512, visible=False)
|
219 |
gr.Examples(
|
220 |
+
examples=[["A train crossing a bridge that is going over a body of water", os.path.join("./examples", "example1.jpg")],
|
221 |
+
["The man in the business suit wears a striped blue and white tie", os.path.join("./examples", "example2.jpg")],
|
222 |
+
["A skier stands on a small ledge in the snow",os.path.join("./examples", "example3.jpg")],
|
223 |
+
["The bathroom with green tile and a red shower curtain", os.path.join("./examples", "example4.jpg")]],
|
224 |
inputs = [textbox, dummy_img_output])
|
225 |
|
226 |
+
# vote_list = [Top1_btn, Top2_btn, Top3_btn, Top4_btn, Revote_btn, Submit_btn]
|
227 |
+
order_btn_list = [send_btn, draw_btn, clear_btn]
|
228 |
+
vote_order_list = [leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
|
|
229 |
A1_btn, A2_btn, A3_btn, A4_btn, B1_btn, B2_btn, B3_btn, B4_btn, C1_btn, C2_btn, C3_btn, C4_btn, D1_btn, D2_btn, D3_btn, D4_btn, \
|
230 |
vote_textbox, vote_submit_btn, vote_mode_btn]
|
231 |
# vote_rank_list = [A1_btn, A2_btn, A3_btn, A4_btn, B1_btn, B2_btn, B3_btn, B4_btn, C1_btn, C2_btn, C3_btn, C4_btn, D1_btn, D2_btn, D3_btn, D4_btn]
|
|
|
262 |
window3_text = gr.Textbox(value="Model C", visible=False, interactive=False)
|
263 |
window4_text = gr.Textbox(value="Model D", visible=False, interactive=False)
|
264 |
vote_level = gr.Number(value=0, visible=False, interactive=False)
|
265 |
+
# Top1_btn.click(reset_level, inputs=[Top1_text], outputs=[vote_level])
|
266 |
+
# Top2_btn.click(reset_level, inputs=[Top2_text], outputs=[vote_level])
|
267 |
+
# Top3_btn.click(reset_level, inputs=[Top3_text], outputs=[vote_level])
|
268 |
+
# Top4_btn.click(reset_level, inputs=[Top4_text], outputs=[vote_level])
|
269 |
vote_mode = gr.Textbox(value="Best", visible=False, interactive=False)
|
270 |
right_vote_text = gr.Textbox(value="wrong", visible=False, interactive=False)
|
271 |
|
|
|
301 |
outputs=vote_order_list
|
302 |
)
|
303 |
|
304 |
+
# draw_btn.click(
|
305 |
+
# gen_func_random,
|
306 |
+
# inputs=[state0, state1, state2, state3, model_selector_left, model_selector_left1, model_selector_right, model_selector_right1],
|
307 |
+
# outputs=[state0, state1, state2, state3, generate_ig0, generate_ig1, generate_ig2, generate_ig3, chatbot_left, chatbot_left1, chatbot_right, chatbot_right1, \
|
308 |
+
# textbox, model_selector_left, model_selector_left1, model_selector_right, model_selector_right1],
|
309 |
+
# api_name="draw_btn_annony"
|
310 |
+
# ).then(
|
311 |
+
# disable_order_buttons,
|
312 |
+
# inputs=None,
|
313 |
+
# outputs=order_btn_list
|
314 |
+
# ).then(
|
315 |
+
# enable_vote_mode_buttons,
|
316 |
+
# inputs=[vote_mode],
|
317 |
+
# outputs=vote_order_list
|
318 |
+
# )
|
319 |
draw_btn.click(
|
320 |
+
get_random_mscoco_prompt,
|
321 |
+
inputs=None,
|
322 |
+
outputs=[textbox],
|
|
|
323 |
api_name="draw_btn_annony"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
)
|
|
|
|
|
|
|
|
|
|
|
325 |
|
326 |
clear_btn.click(
|
327 |
clear_history_side_by_side_anony,
|
|
|
333 |
enable_order_buttons,
|
334 |
inputs=None,
|
335 |
outputs=order_btn_list
|
|
|
|
|
|
|
|
|
336 |
).then(
|
337 |
clear_rank,
|
338 |
inputs=[rank, vote_level],
|
|
|
355 |
# outputs=btn_list
|
356 |
# )
|
357 |
vote_mode_btn.click(
|
358 |
+
reset_chatbot,
|
359 |
+
inputs=[vote_mode, generate_ig0, generate_ig1, generate_ig2, generate_ig3],
|
360 |
+
outputs=[chatbot_left, chatbot_left1, chatbot_right, chatbot_right1]
|
361 |
+
).then(
|
362 |
reset_mode,
|
363 |
inputs=[vote_mode],
|
364 |
+
outputs=[leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
365 |
A1_btn, A2_btn, A3_btn, A4_btn, B1_btn, B2_btn, B3_btn, B4_btn, C1_btn, C2_btn, C3_btn, C4_btn, D1_btn, D2_btn, D3_btn, D4_btn, \
|
366 |
vote_textbox, vote_submit_btn, vote_mode_btn, vote_mode]
|
367 |
+
)
|
368 |
+
|
369 |
vote_textbox.submit(
|
370 |
text_response_rank_igm,
|
371 |
inputs=[generate_ig0, generate_ig1, generate_ig2, generate_ig3, Top1_text, Top2_text, Top3_text, Top4_text, vote_textbox],
|
372 |
outputs=[chatbot_left, chatbot_left1, chatbot_right, chatbot_right1, vote_textbox, right_vote_text, rank]
|
373 |
+
).then(
|
374 |
+
disable_vote,
|
375 |
+
inputs=None,
|
376 |
+
outputs=[vote_submit_btn, vote_mode_btn]
|
377 |
).then(
|
378 |
submit_response_rank_igm,
|
379 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rank, right_vote_text],
|
|
|
386 |
text_response_rank_igm,
|
387 |
inputs=[generate_ig0, generate_ig1, generate_ig2, generate_ig3, Top1_text, Top2_text, Top3_text, Top4_text, vote_textbox],
|
388 |
outputs=[chatbot_left, chatbot_left1, chatbot_right, chatbot_right1, vote_textbox, right_vote_text, rank]
|
389 |
+
).then(
|
390 |
+
disable_vote,
|
391 |
+
inputs=None,
|
392 |
+
outputs=[vote_submit_btn, vote_mode_btn]
|
393 |
).then(
|
394 |
submit_response_rank_igm,
|
395 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rank, right_vote_text],
|
|
|
456 |
leftvote_btn.click(
|
457 |
submit_response_igm,
|
458 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankA],
|
459 |
+
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
460 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
461 |
vote_mode_btn]
|
462 |
)
|
463 |
left1vote_btn.click(
|
464 |
submit_response_igm,
|
465 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankB],
|
466 |
+
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
467 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
468 |
vote_mode_btn]
|
469 |
)
|
470 |
rightvote_btn.click(
|
471 |
submit_response_igm,
|
472 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankC],
|
473 |
+
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
474 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
475 |
vote_mode_btn]
|
476 |
)
|
477 |
right1vote_btn.click(
|
478 |
submit_response_igm,
|
479 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankD],
|
480 |
+
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
481 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
482 |
vote_mode_btn]
|
483 |
)
|
484 |
tie_btn.click(
|
485 |
submit_response_igm,
|
486 |
inputs=[state0, state1, state2, state3, dummy_left_model, dummy_left1_model, dummy_right_model, dummy_right1_model, rankTie],
|
487 |
+
outputs=[textbox, leftvote_btn, left1vote_btn, rightvote_btn, right1vote_btn, tie_btn, \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
model_selector_left, model_selector_left1, model_selector_right, model_selector_right1, \
|
489 |
vote_mode_btn]
|
490 |
)
|
serve/update_skill.py
CHANGED
@@ -6,9 +6,8 @@ import io, os
|
|
6 |
import sys
|
7 |
from serve.constants import SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD, SSH_SKILL
|
8 |
trueskill_env = TrueSkill()
|
9 |
-
|
10 |
-
|
11 |
-
group = []
|
12 |
|
13 |
|
14 |
def ucb_score(trueskill_diff, t, n):
|
@@ -56,10 +55,16 @@ def load_json_via_sftp():
|
|
56 |
return ratings, comparison_counts, total_comparisons
|
57 |
|
58 |
|
59 |
-
def update_skill(rank, k_group=4):
|
60 |
|
61 |
ratings, comparison_counts, total_comparisons = load_json_via_sftp()
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
pairwise_comparisons = [(i, j) for i in range(len(group)) for j in range(i+1, len(group))]
|
64 |
for player1, player2 in pairwise_comparisons:
|
65 |
if rank[player1] < rank[player2]:
|
@@ -73,5 +78,7 @@ def update_skill(rank, k_group=4):
|
|
73 |
|
74 |
comparison_counts[group[player1], group[player2]] += 1
|
75 |
comparison_counts[group[player2], group[player1]] += 1
|
|
|
|
|
76 |
|
77 |
save_json_via_sftp(ratings, comparison_counts, total_comparisons)
|
|
|
6 |
import sys
|
7 |
from serve.constants import SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD, SSH_SKILL
|
8 |
trueskill_env = TrueSkill()
|
9 |
+
sys.path.append('../')
|
10 |
+
from model.models import IMAGE_GENERATION_MODELS
|
|
|
11 |
|
12 |
|
13 |
def ucb_score(trueskill_diff, t, n):
|
|
|
55 |
return ratings, comparison_counts, total_comparisons
|
56 |
|
57 |
|
58 |
+
def update_skill(rank, model_names, k_group=4):
|
59 |
|
60 |
ratings, comparison_counts, total_comparisons = load_json_via_sftp()
|
61 |
+
|
62 |
+
# group = Model_ID.group
|
63 |
+
group = []
|
64 |
+
for model_name in model_names:
|
65 |
+
group.append(IMAGE_GENERATION_MODELS.index(model_name))
|
66 |
+
print(group)
|
67 |
+
|
68 |
pairwise_comparisons = [(i, j) for i in range(len(group)) for j in range(i+1, len(group))]
|
69 |
for player1, player2 in pairwise_comparisons:
|
70 |
if rank[player1] < rank[player2]:
|
|
|
78 |
|
79 |
comparison_counts[group[player1], group[player2]] += 1
|
80 |
comparison_counts[group[player2], group[player1]] += 1
|
81 |
+
|
82 |
+
total_comparisons += 1
|
83 |
|
84 |
save_json_via_sftp(ratings, comparison_counts, total_comparisons)
|
serve/upload.py
CHANGED
@@ -4,7 +4,8 @@ import io, os
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
import json
|
7 |
-
|
|
|
8 |
|
9 |
def create_ssh_client(server, port, user, password):
|
10 |
ssh = paramiko.SSHClient()
|
@@ -47,6 +48,25 @@ def upload_informance(data, data_path):
|
|
47 |
pass
|
48 |
# ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
|
49 |
# upload_json_via_sftp(ssh, data, data_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
def create_remote_directory(remote_directory):
|
52 |
ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
|
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
import json
|
7 |
+
import random
|
8 |
+
from .constants import SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD, SSH_LOG, SSH_MSCOCO
|
9 |
|
10 |
def create_ssh_client(server, port, user, password):
|
11 |
ssh = paramiko.SSHClient()
|
|
|
48 |
pass
|
49 |
# ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
|
50 |
# upload_json_via_sftp(ssh, data, data_path)
|
51 |
+
def get_random_mscoco_prompt():
|
52 |
+
ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
|
53 |
+
sftp = ssh.open_sftp()
|
54 |
+
files = sftp.listdir(SSH_MSCOCO)
|
55 |
+
txt_files = [file for file in files if file.endswith('.txt')]
|
56 |
+
|
57 |
+
selected_files = random.sample(txt_files, 1) # get one prompt
|
58 |
+
|
59 |
+
for file in selected_files:
|
60 |
+
remote_file_path = os.path.join(SSH_MSCOCO, file)
|
61 |
+
with sftp.file(remote_file_path, 'r') as f:
|
62 |
+
content = f.read().decode('utf-8')
|
63 |
+
print(f"Content of {file}:")
|
64 |
+
print("\n")
|
65 |
+
sftp.close()
|
66 |
+
ssh.close()
|
67 |
+
|
68 |
+
return content
|
69 |
+
|
70 |
|
71 |
def create_remote_directory(remote_directory):
|
72 |
ssh = create_ssh_client(SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD)
|
serve/utils.py
CHANGED
@@ -46,7 +46,6 @@ acknowledgment_md = """
|
|
46 |
<p> Our codebase is built upon <a href="https://github.com/lm-sys/FastChat" target="_blank">FastChat</a>, <a href="https://github.com/TIGER-AI-Lab/ImagenHub" target="_blank">ImagenHub</a> and <a href="https://github.com/TIGER-AI-Lab/VideoGenHub" target="_blank">VideoGenHub</a>.</p>
|
47 |
</div>
|
48 |
"""
|
49 |
-
color = "rgb(49, 139, 190)"
|
50 |
block_css = """
|
51 |
#notice_markdown {
|
52 |
font-size: 110%
|
@@ -100,11 +99,53 @@ footer {
|
|
100 |
.custom-button {
|
101 |
border-radius: 8px;
|
102 |
}
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
# .custom-button {
|
109 |
# padding: 10px 15px;
|
110 |
# text-align: center;
|
@@ -134,26 +175,27 @@ def enable_vote_buttons():
|
|
134 |
return tuple(gr.update(visible=True, interactive=i<=4) for i in range(6))
|
135 |
def disable_vote_buttons():
|
136 |
return tuple(gr.update(visible=False, interactive=False) for i in range(6))
|
137 |
-
|
|
|
138 |
def enable_vote_mode_buttons(mode):
|
139 |
print(mode)
|
140 |
if mode == "Best":
|
141 |
-
return (gr.update(visible=True, interactive=True),) *
|
142 |
(gr.update(visible=False, interactive=False),) * 16 + \
|
143 |
(gr.update(visible=True, interactive=False),) * 2 + \
|
144 |
(gr.update(visible=True, interactive=True),)
|
145 |
elif mode == "Rank":
|
146 |
-
return (gr.update(visible=False, interactive=False),) *
|
147 |
(gr.update(visible=True, interactive=True),) * 16 + \
|
148 |
(gr.update(visible=True, interactive=True),) * 3
|
149 |
def disable_vote_mode_buttons():
|
150 |
-
return tuple(gr.update(visible=False, interactive=False) for _ in range(
|
151 |
|
152 |
|
153 |
def enable_order_buttons():
|
154 |
-
return tuple(gr.update(interactive=True) for _ in range(
|
155 |
def disable_order_buttons():
|
156 |
-
return (gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=True)
|
157 |
|
158 |
def clear_history():
|
159 |
return None, "", None
|
|
|
46 |
<p> Our codebase is built upon <a href="https://github.com/lm-sys/FastChat" target="_blank">FastChat</a>, <a href="https://github.com/TIGER-AI-Lab/ImagenHub" target="_blank">ImagenHub</a> and <a href="https://github.com/TIGER-AI-Lab/VideoGenHub" target="_blank">VideoGenHub</a>.</p>
|
47 |
</div>
|
48 |
"""
|
|
|
49 |
block_css = """
|
50 |
#notice_markdown {
|
51 |
font-size: 110%
|
|
|
99 |
.custom-button {
|
100 |
border-radius: 8px;
|
101 |
}
|
102 |
+
.best-button {
|
103 |
+
border-radius: 8px;
|
104 |
+
}
|
105 |
+
.row {
|
106 |
+
display: flex;
|
107 |
+
justify-content: space-between;
|
108 |
+
}
|
109 |
+
.send-button {
|
110 |
+
color: white;
|
111 |
+
}
|
112 |
+
.submit-button {
|
113 |
+
color: red;
|
114 |
+
}
|
115 |
+
#btncolor1 {background: rgb(168, 230, 207);}
|
116 |
+
#btncolor2 {background: rgb(253, 255, 171);}
|
117 |
+
#btncolor3 {background: rgb(255, 211, 182);}
|
118 |
+
#btncolor4 {background: rgb(255, 170, 165);}
|
119 |
+
|
120 |
+
#btnblue {background: rgb(0, 187, 240);}
|
121 |
+
#btnpink {background: rgb(255, 168, 184);}
|
122 |
"""
|
123 |
+
|
124 |
+
#btncolor1 {background: rgb(128, 214, 255);}
|
125 |
+
#btncolor2 {background: rgb(237, 247, 152);}
|
126 |
+
#btncolor3 {background: rgb(250, 181, 122);}
|
127 |
+
#btncolor4 {background: rgb(240, 104, 104);}
|
128 |
+
|
129 |
+
#btncolor1 {background: rgb(112, 161, 215);}
|
130 |
+
#btncolor2 {background: rgb(161, 222, 147);}
|
131 |
+
#btncolor3 {background: rgb(247, 244, 139);}
|
132 |
+
#btncolor4 {background: rgb(244, 124, 124);}
|
133 |
+
|
134 |
+
#btncolor1 {background: rgb(168, 230, 207);}
|
135 |
+
#btncolor2 {background: rgb(253, 255, 171);}
|
136 |
+
#btncolor3 {background: rgb(255, 211, 182);}
|
137 |
+
#btncolor4 {background: rgb(255, 170, 165);}
|
138 |
+
|
139 |
+
#btncolor1 {background: rgb(255, 212, 96);}
|
140 |
+
#btncolor2 {background: rgb(240, 123, 63);}
|
141 |
+
#btncolor3 {background: rgb(234, 84, 85);}
|
142 |
+
#btncolor4 {background: rgb(45, 64, 89);}
|
143 |
+
|
144 |
+
#btncolor1 {background: rgb(255, 189, 57);}
|
145 |
+
#btncolor2 {background: rgb(230, 28, 93);}
|
146 |
+
#btncolor3 {background: rgb(147, 0, 119);}
|
147 |
+
#btncolor4 {background: rgb(58, 0, 136);}
|
148 |
+
# max-width: 100px;
|
149 |
# .custom-button {
|
150 |
# padding: 10px 15px;
|
151 |
# text-align: center;
|
|
|
175 |
return tuple(gr.update(visible=True, interactive=i<=4) for i in range(6))
|
176 |
def disable_vote_buttons():
|
177 |
return tuple(gr.update(visible=False, interactive=False) for i in range(6))
|
178 |
+
def disable_vote():
|
179 |
+
return (gr.update(interactive=False), gr.update(interactive=False))
|
180 |
def enable_vote_mode_buttons(mode):
|
181 |
print(mode)
|
182 |
if mode == "Best":
|
183 |
+
return (gr.update(visible=True, interactive=True),) * 5 + \
|
184 |
(gr.update(visible=False, interactive=False),) * 16 + \
|
185 |
(gr.update(visible=True, interactive=False),) * 2 + \
|
186 |
(gr.update(visible=True, interactive=True),)
|
187 |
elif mode == "Rank":
|
188 |
+
return (gr.update(visible=False, interactive=False),) * 5 + \
|
189 |
(gr.update(visible=True, interactive=True),) * 16 + \
|
190 |
(gr.update(visible=True, interactive=True),) * 3
|
191 |
def disable_vote_mode_buttons():
|
192 |
+
return tuple(gr.update(visible=False, interactive=False) for _ in range(24))
|
193 |
|
194 |
|
195 |
def enable_order_buttons():
|
196 |
+
return tuple(gr.update(interactive=True) for _ in range(3))
|
197 |
def disable_order_buttons():
|
198 |
+
return (gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=True))
|
199 |
|
200 |
def clear_history():
|
201 |
return None, "", None
|