Spaces:
Running
Running
File size: 6,797 Bytes
12cd134 8327f59 12cd134 904bfa4 12cd134 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
import json
import gradio as gr
# from validate import StyleImageDatabase
JSON_FILE_NAME = 'styles.json'
def get_grouped_images_from_database():
database = StyleImageDatabase()
images = database.get_all_style_images()
grouped_images = {}
for image in images:
style_id = image[1]
style_name = image[2]
request_image_url = image[3]
result_image_url = image[4]
if style_id not in grouped_images:
grouped_images[style_id] = {'style_name': style_name, 'images': []}
image_data = {'result_image_url': result_image_url, 'request_image_url': request_image_url}
grouped_images[style_id]['images'].append(image_data)
return grouped_images
def save_images_to_json_file(grouped_images):
with open(JSON_FILE_NAME, 'w') as json_file:
json.dump(grouped_images, json_file, indent=4)
def load_images_from_json_file():
with open(JSON_FILE_NAME, 'r') as json_file:
return json.load(json_file)
def get_test_images():
return {
"Lukas": "https://cc.cz/wp-content/uploads/2020/10/lukas_strandel_ceo_futured_01-1.jpg",
"Jana": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-10-36-19-IMG_7058 2 1.jpg",
"Honzík1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-10-33-39-IMG_20210401_210045_869.jpg",
"Radek1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-27-12-34-30-IMG_0422.jpg",
"Radek2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-08-31-18-radek_selfie.jpeg",
"Bezo1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-10-47-10-IMG_3670 1.jpeg",
"Bezo2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-10-38-40-IMG_3845.jpeg",
"David": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-10-38-40-56798776 1.jpg",
"Kalman": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-08-31-18-kalman.jpg",
"Lenka": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-08-31-18-lenka.jpg",
"Kotal": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-08-31-18-kotal.png",
"Sumera1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-09-02-18-martin.jpg",
"Sumera2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-08-31-18-martin_sucks.jpg",
"Lada": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-03-28-08-31-18-lada.jpg",
"Vladka1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-08-8264DE74-B9CE-477C-8883-CD5699C41B45.JPG",
"Radek3": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-10-IMG_0558.jpg",
"Pollak": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-13-PXL_20211217_185315324.jpg",
"Martina1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-19-IMG_7157.jpg",
"Vox1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-23-1000044348.jpg",
"Sarka1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-26-IMG_6809.jpg",
"Ruda1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-30-IMG_0104.JPG",
"Matsem": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-32-PXL_20240412_133830638.MP.jpg",
"Martina2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-36-IMG_6007.jpg",
"Radek4": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-41-IMG_9661.jpg",
"Matej G. 1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-44-IMG_8423.jpg",
"Marie1": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-45-IMG_2294.jpg",
"Sarka2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-46-IMG_7474.jpg",
"Matej G. 2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-51-IMG_6556.jpg",
"Ruda2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-52-IMG_0586.jpg",
"Marie2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-55-IMG_0381.jpg",
"Vox2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-56-1000052742.jpg",
"Vladka2": "https://mdevcamp-ai-upload-script.s3.amazonaws.com/images/2024-04-15-10-50-59-51E641DC-CEB1-4786-BE5B-56D443790907.JPG",
"Honzik2": "https://storage.googleapis.com/mdevcamp-avatars/source/af146193-f350-11ee-9eb3-4200a9fe0102",
"Honzik3": "https://storage.googleapis.com/mdevcamp-avatars/source/9386c6f4-f654-11ee-9eb3-4200a9fe0102",
"Simon1": "https://storage.googleapis.com/mdevcamp-avatars/source/bcd9af2b-f6ac-11ee-9eb3-4200a9fe0102",
"Simon2": "https://storage.googleapis.com/mdevcamp-avatars/source/f798bc1b-f70d-11ee-9eb3-4200a9fe0102",
"Simon3": "https://storage.googleapis.com/mdevcamp-avatars/source/b922a19c-f70a-11ee-9eb3-4200a9fe0102",
"Patrik": "https://storage.googleapis.com/mdevcamp-avatars/source/9c178993-f71e-11ee-9eb3-4200a9fe0102",
"Patrik2": "https://storage.googleapis.com/mdevcamp-avatars/source/f3bd8696-f71a-11ee-9eb3-4200a9fe0102",
"Patrik3": "https://storage.googleapis.com/mdevcamp-avatars/source/af3b30ef-f713-11ee-9eb3-4200a9fe0102",
}
if __name__ == "__main__":
# database = StyleImageDatabase()
# grouped_images = get_grouped_images_from_database()
# save_images_to_json_file(grouped_images)
loaded_images = load_images_from_json_file()
test_images_with_names = get_test_images()
inverted_test_images_with_names = {v: k for k, v in test_images_with_names.items()}
with gr.Blocks() as demo:
for style_id, data in loaded_images.items():
with gr.Accordion(label=f"Style {data['style_name']} - {style_id}", open=False):
with gr.Row():
images = [(image['result_image_url'], inverted_test_images_with_names.get(image['request_image_url'], image['request_image_url'])) for image in data['images']]
gr.Gallery(
label="Results",
value=images,
show_label=False,
elem_id="gallery",
columns=[5],
rows=[10],
object_fit="contain",
height="auto",
)
demo.launch()
|