File size: 5,606 Bytes
c428c06
c8710a3
0fe8471
df7b421
0fe8471
df7b421
 
 
 
 
0fe8471
 
df7b421
0fe8471
 
df7b421
0fe8471
 
df7b421
0fe8471
df7b421
 
 
 
 
 
14b0859
82feb26
 
 
 
afb8405
82feb26
14b0859
 
 
c8710a3
 
 
 
14b0859
 
 
 
 
82feb26
14b0859
82feb26
 
14b0859
82feb26
 
14b0859
82feb26
 
 
 
 
 
 
 
 
 
 
 
 
 
df7b421
0fe8471
df7b421
1960f8c
14b0859
0fe8471
 
 
14b0859
 
1960f8c
14b0859
1960f8c
14b0859
c8710a3
 
 
14b0859
 
 
 
afb8405
 
 
14b0859
 
 
 
 
 
1960f8c
 
 
 
14b0859
 
 
1960f8c
 
 
14b0859
 
0fe8471
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
108
109
110
111
import gradio as gr
from PIL import Image
import json
import os

# Obtener la ruta absoluta para guardar el archivo en el directorio actual
def get_file_path(filename):
    return os.path.join(os.getcwd(), filename)

# Cargar puntuaciones Elo desde un archivo JSON
def load_elo_scores():
    try:
        with open(get_file_path("elo_scores.json"), "r") as f:
            return json.load(f)
    except FileNotFoundError:
        # Si el archivo no existe, inicializamos las puntuaciones
        return {"DALL-E 3": 1000, "Midjourney 6.1": 1000, "Flux": 1000}

# Guardar puntuaciones Elo en un archivo JSON
def save_elo_scores(elo_scores):
    try:
        with open(get_file_path("elo_scores.json"), "w") as f:
            json.dump(elo_scores, f)
        print("Puntuaciones guardadas correctamente en elo_scores.json")
    except Exception as e:
        print(f"Error al guardar el archivo: {e}")

# Funci贸n para calcular la actualizaci贸n de Elo
def elo_update(winner_elo, loser_elo, k=32):
    expected_score_winner = 1 / (1 + 10 ** ((loser_elo - winner_elo) / 400))
    new_winner_elo = winner_elo + k * (1 - expected_score_winner)
    new_loser_elo = loser_elo + k * (0 - (1 - expected_score_winner))
    return new_winner_elo, new_loser_elo

# Cargar im谩genes predefinidas
def load_images():
    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

    # Primera elecci贸n
    if first == "DALL-E 3":
        elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"] = elo_update(elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"])
        elo_scores["DALL-E 3"], elo_scores["Flux"] = elo_update(elo_scores["DALL-E 3"], elo_scores["Flux"])
    elif first == "Midjourney 6.1":
        elo_scores["Midjourney 6.1"], elo_scores["DALL-E 3"] = elo_update(elo_scores["Midjourney 6.1"], elo_scores["DALL-E 3"])
        elo_scores["Midjourney 6.1"], elo_scores["Flux"] = elo_update(elo_scores["Midjourney 6.1"], elo_scores["Flux"])
    elif first == "Flux":
        elo_scores["Flux"], elo_scores["DALL-E 3"] = elo_update(elo_scores["Flux"], elo_scores["DALL-E 3"])
        elo_scores["Flux"], elo_scores["Midjourney 6.1"] = elo_update(elo_scores["Flux"], elo_scores["Midjourney 6.1"])

    # Segunda elecci贸n
    if second == "DALL-E 3":
        elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"] = elo_update(elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"])
        elo_scores["DALL-E 3"], elo_scores["Flux"] = elo_update(elo_scores["DALL-E 3"], elo_scores["Flux"])
    elif second == "Midjourney 6.1":
        elo_scores["Midjourney 6.1"], elo_scores["DALL-E 3"] = elo_update(elo_scores["Midjourney 6.1"], elo_scores["DALL-E 3"])
        elo_scores["Midjourney 6.1"], elo_scores["Flux"] = elo_update(elo_scores["Midjourney 6.1"], elo_scores["Flux"])
    elif second == "Flux":
        elo_scores["Flux"], elo_scores["DALL-E 3"] = elo_update(elo_scores["Flux"], elo_scores["DALL-E 3"])
        elo_scores["Flux"], elo_scores["Midjourney 6.1"] = elo_update(elo_scores["Flux"], elo_scores["Midjourney 6.1"])

    # Guardar las puntuaciones actualizadas en el archivo
    save_elo_scores(elo_scores)
    
    return elo_scores["DALL-E 3"], elo_scores["Midjourney 6.1"], elo_scores["Flux"]

# Cargar las puntuaciones Elo
elo_scores = load_elo_scores()

# Interfaz Gradio
def vote(first, second, third):
    dalle3_score, midjourney_score, flux_score = update_elo(first, second, third)
    dalle3_image, midjourney_image, flux_image = load_images()
    return dalle3_image, midjourney_image, flux_image, f"DALL-E 3: {round(dalle3_score)}", f"Midjourney 6.1: {round(midjourney_score)}", f"Flux: {round(flux_score)}"

# Cargar im谩genes al inicio
dalle3_image, midjourney_image, flux_image = load_images()

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_img = gr.Image(value=dalle3_image, label="DALL-E 3", interactive=False, height=512, width=512)
    midjourney_img = gr.Image(value=midjourney_image, label="Midjourney 6.1", interactive=False, height=512, width=512)
    flux_img = gr.Image(value=flux_image, label="Flux", interactive=False, height=512, width=512)

    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")
    
    with gr.Row():
        dalle3_score_text = gr.Textbox(value=f"DALL-E 3: {elo_scores['DALL-E 3']}", label="Puntuaci贸n DALL-E 3", interactive=False)
        midjourney_score_text = gr.Textbox(value=f"Midjourney 6.1: {elo_scores['Midjourney 6.1']}", label="Puntuaci贸n Midjourney 6.1", interactive=False)
        flux_score_text = gr.Textbox(value=f"Flux: {elo_scores['Flux']}", label="Puntuaci贸n Flux", interactive=False)

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

    vote_button.click(vote, inputs=[first_choice, second_choice, third_choice], 
                      outputs=[dalle3_img, midjourney_img, flux_img, 
                               dalle3_score_text, midjourney_score_text, flux_score_text])

demo.launch()