File size: 2,977 Bytes
14b0859
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image
from elo import Elo

# Inicializa el sistema de puntuaci贸n Elo
elo_system = Elo(k=32)

# Inicializa puntuaciones Elo
elo_scores = {
    "DALL-E 3": 1000,
    "Midjourney 6.1": 1000,
    "Flux": 1000,
}

# Cargar im谩genes predefinidas
def load_images():
    # Aseg煤rate de que los archivos de im谩genes coincidan con estos nombres
    dalle3_image = Image.open("images/dalle3_image.png")
    midjourney_image = Image.open("images/midjourney_image.png")
    flux_image = Image.open("images/flux_image.png")
    return dalle3_image, midjourney_image, flux_image

# Actualizar el puntaje Elo basado en la votaci贸n
def update_elo(first, second, third):
    global elo_scores

    if first == "DALL-E 3":
        elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"] = elo_system.rate_match(elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"])
        elo_scores["DALL-E 3"], elo_scores["Flux"] = elo_system.rate_match(elo_scores["DALL-E 3"], elo_scores["Flux"])
    elif first == "Midjourney 6.1":
        elo_scores["Midjourney 6.1"], elo_scores["DALL-E 3"] = elo_system.rate_match(elo_scores["Midjourney 6.1"], elo_scores["DALL-E 3"])
        elo_scores["Midjourney 6.1"], elo_scores["Flux"] = elo_system.rate_match(elo_scores["Midjourney 6.1"], elo_scores["Flux"])
    elif first == "Flux":
        elo_scores["Flux"], elo_scores["DALL-E 3"] = elo_system.rate_match(elo_scores["Flux"], elo_scores["DALL-E 3"])
        elo_scores["Flux"], elo_scores["Midjourney 6.1"] = elo_system.rate_match(elo_scores["Flux"], elo_scores["Midjourney 6.1"])

    return f"DALL-E 3: {elo_scores['DALL-E 3']}, Midjourney 6.1: {elo_scores['Midjourney 6.1']}, Flux: {elo_scores['Flux']}"

# Interfaz Gradio
def vote(first, second, third):
    updated_scores = update_elo(first, second, third)
    dalle3_image, midjourney_image, flux_image = load_images()
    return dalle3_image, midjourney_image, flux_image, updated_scores

with gr.Blocks() as demo:
    gr.Markdown("# Akelarre Generativo (DALL-E 3 vs MJ 6.1 vs Flux 1)")
    gr.Markdown("### Vota por la imagen generada por IA que prefieras. La puntuaci贸n Elo se actualizar谩 en tiempo real.")

    dalle3_image = gr.Image(label="DALL-E 3", interactive=False)
    midjourney_image = gr.Image(label="Midjourney 6.1", interactive=False)
    flux_image = gr.Image(label="Flux", interactive=False)

    with gr.Row():
        first_choice = gr.Dropdown(["DALL-E 3", "Midjourney 6.1", "Flux"], label="Primera Favorita")
        second_choice = gr.Dropdown(["DALL-E 3", "Midjourney 6.1", "Flux"], label="Segunda Favorita")
        third_choice = gr.Dropdown(["DALL-E 3", "Midjourney 6.1", "Flux"], label="Tercera Favorita")
    
    elo_scores_text = gr.Textbox(label="Puntuaci贸n Elo")

    vote_button = gr.Button("Votar y Actualizar")

    vote_button.click(vote, inputs=[first_choice, second_choice, third_choice], outputs=[dalle3_image, midjourney_image, flux_image, elo_scores_text])

demo.launch()