Spaces:
Sleeping
Sleeping
upload
Browse files- __pycache__/db.cpython-310.pyc +0 -0
- app.py +129 -4
- app.pyi +133 -0
- db.py +47 -0
- file_list.txt +0 -0
- requirements.txt +1 -0
__pycache__/db.cpython-310.pyc
ADDED
Binary file (1.48 kB). View file
|
|
app.py
CHANGED
@@ -1,7 +1,132 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from functools import partial
|
3 |
+
import random
|
4 |
+
import os
|
5 |
+
from db import send_message_to_mongodb
|
6 |
+
all_property = ['artifact', 'color', 'noise', 'lightness', 'blury']
|
7 |
+
property_dict = {
|
8 |
+
'artifact': 'less artifact',
|
9 |
+
'color': 'pleasant color',
|
10 |
+
'noise': 'less noise',
|
11 |
+
'lightness': 'Illuminated',
|
12 |
+
'blury': 'sharp boundary'
|
13 |
+
}
|
14 |
+
methods = ['IMGS_bread', 'IMGS_iat', 'retinexformer_png', 'images', 'IMGS_Kind', 'IMGS_ZeroDCE', 'IMGS_nerco']
|
15 |
+
method_dict = {
|
16 |
+
'IMGS_bread': 'Bread',
|
17 |
+
'IMGS_iat': 'IAT',
|
18 |
+
'retinexformer_png': 'Retinexformer',
|
19 |
+
'images': 'Original Input',
|
20 |
+
'IMGS_Kind': 'Kind',
|
21 |
+
'IMGS_ZeroDCE': 'ZeroDCE',
|
22 |
+
'IMGS_nerco': 'NeRCo'
|
23 |
+
}
|
24 |
+
core_file = './file_list.txt'
|
25 |
+
bucket = os.getenv('bucket') #'https://checkpoints.mingjia.li/Exdark/'
|
26 |
+
image_list = []
|
27 |
+
with open(core_file, 'r') as f:
|
28 |
+
for line in f:
|
29 |
+
if line.strip().endswith('.png'):
|
30 |
+
image_list.append(line.strip())
|
31 |
|
|
|
|
|
32 |
|
33 |
+
class RandomState(gr.State):
|
34 |
+
def __init__(self, image, method1, method2, property):
|
35 |
+
super().__init__()
|
36 |
+
self.image = image
|
37 |
+
self.method1 = method1
|
38 |
+
self.method2 = method2
|
39 |
+
self.property = property
|
40 |
+
|
41 |
+
|
42 |
+
def compare_images(image1, image2):
|
43 |
+
return "Click on the better image."
|
44 |
+
with gr.Blocks() as block_demo:
|
45 |
+
|
46 |
+
def get_random_comparison():
|
47 |
+
import time
|
48 |
+
print(time.time())
|
49 |
+
random.seed(time.time())
|
50 |
+
image = random.choice(image_list)
|
51 |
+
method1, method2 = random.sample(methods, 2)
|
52 |
+
image1 = bucket + '/' + method1 + '/' + image
|
53 |
+
image2 = bucket + '/' + method2 + '/' + image
|
54 |
+
image_input = bucket + '/images/' + image
|
55 |
+
property = random.choice(all_property)
|
56 |
+
return image, method1, method2, image1, image2, property, image_input
|
57 |
+
|
58 |
+
def refresh_comparison():
|
59 |
+
return get_random_comparison()
|
60 |
+
def on_load(request: gr.Request):
|
61 |
+
headers = request.headers
|
62 |
+
host = request.client.host
|
63 |
+
request_state = dict(headers)
|
64 |
+
request_state['host'] = host
|
65 |
+
# print(str(request))
|
66 |
+
print(request_state)
|
67 |
+
image, method1, method2, image1, image2, property, image_input = refresh_comparison()
|
68 |
+
return image1, image2, f'### Which one is better in terms of **{property_dict[property]}**?',\
|
69 |
+
image, method1, method2, property, image_input, request_state
|
70 |
+
with gr.Row():
|
71 |
+
with gr.Column():
|
72 |
+
gr.Markdown("<h2 style='font-size: 24px;'>Low-light Image Enhancer Arena 🥊</h2>")
|
73 |
+
gr.Markdown("<p style='font-size: 18px;'>This is a simple arena to test the performance of different low-light image enhancers.</p>")
|
74 |
+
gr.Markdown("<p style='font-size: 18px;'>Please help us to find the better image!</p>")
|
75 |
+
gr.Markdown("<p style='font-size: 18px;'>Failures:</p>")
|
76 |
+
gr.Markdown("<ul style='font-size: 18px;'>"
|
77 |
+
f"<li><strong>Artifact:</strong> - There might be unwanted or unintended alterations in the image.</li>"
|
78 |
+
f"<li><strong>Color Degradation:</strong> - The color recoverd from low-light input is not the same as the color in the input image.</li>"
|
79 |
+
f"<li><strong>Noise:</strong> - There might be noise in the image.</li>"
|
80 |
+
f"<li><strong>Poor Illumination:</strong> - The brightness level of the image is not good, it might be too dark or too bright.</li>"
|
81 |
+
f"<li><strong>Blury:</strong> - The sharpness of the image is not good, it might be too blurry or too sharp.</li>"
|
82 |
+
"</ul>")
|
83 |
+
img_input = gr.Image(label="Input Image")
|
84 |
+
|
85 |
+
|
86 |
+
with gr.Row():
|
87 |
+
img1 = gr.Image(label="Image 1")
|
88 |
+
img2 = gr.Image(label="Image 2")
|
89 |
+
|
90 |
+
prop_text = gr.Markdown(f'###Which one is better in terms of x?')
|
91 |
+
image_state, method1_state, method2_state, property_state, ip_state = gr.State(), gr.State(), gr.State(), gr.State(), gr.State()
|
92 |
+
block_demo.load(on_load, inputs=[], outputs=[img1, img2, prop_text,
|
93 |
+
image_state, method1_state, method2_state, property_state, img_input, ip_state])
|
94 |
+
with gr.Row():
|
95 |
+
l_butt = gr.Button("Left is better")
|
96 |
+
r_butt = gr.Button("Right is better")
|
97 |
+
with gr.Row():
|
98 |
+
both_good = gr.Button("Both are good")
|
99 |
+
both_bad = gr.Button("Both are bad")
|
100 |
+
|
101 |
+
result = gr.Markdown("")
|
102 |
+
lnote, rnote = gr.Markdown(""), gr.Markdown("")
|
103 |
+
refresh_butt = gr.Button("Next one", visible=False, interactive=False)
|
104 |
+
# good, bad = gr.State('both_good'), gr.State('both_bad')
|
105 |
+
def update_interface(choice, image, method1, method2, property, ip):
|
106 |
+
# if type(choice) is not str : choice = choice.value
|
107 |
+
print(choice, image, method1, method2, property, ip)
|
108 |
+
send_message_to_mongodb(image, property, method1, method2, choice, ip)
|
109 |
+
# new_image, new_method1, new_method2, new_image1, new_image2, new_property = get_random_comparison()
|
110 |
+
return [
|
111 |
+
# gr.Markdown("### Thanks for your submission!"),
|
112 |
+
gr.Button(interactive=False),
|
113 |
+
gr.Button(interactive=False),
|
114 |
+
gr.Button(interactive=False),
|
115 |
+
gr.Button(interactive=False),
|
116 |
+
# gr.Markdown(f'Left image: {method_dict[method1]}'),
|
117 |
+
# gr.Markdown(f'Right image: {method_dict[method2]}'),
|
118 |
+
gr.Button(visible=True, interactive=True),
|
119 |
+
# gr.Image(new_image1),
|
120 |
+
# gr.Image(new_image2),
|
121 |
+
# f'### Submit your choice for **{new_property}**'
|
122 |
+
]
|
123 |
+
|
124 |
+
l_butt.click(fn=update_interface, inputs=[method1_state, image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
125 |
+
r_butt.click(fn=update_interface, inputs=[method2_state, image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
126 |
+
both_good.click(fn=update_interface, inputs=[gr.State('both_good'), image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
127 |
+
both_bad.click(fn=update_interface, inputs=[gr.State('both_bad'), image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
128 |
+
|
129 |
+
|
130 |
+
refresh_butt.click(None, js="window.location.reload()")
|
131 |
+
|
132 |
+
block_demo.launch()
|
app.pyi
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from functools import partial
|
3 |
+
import random
|
4 |
+
import os
|
5 |
+
from db import send_message_to_mongodb
|
6 |
+
all_property = ['artifact', 'color', 'noise', 'lightness', 'blury']
|
7 |
+
property_dict = {
|
8 |
+
'artifact': 'less artifact',
|
9 |
+
'color': 'pleasant color',
|
10 |
+
'noise': 'less noise',
|
11 |
+
'lightness': 'Illuminated',
|
12 |
+
'blury': 'sharp boundary'
|
13 |
+
}
|
14 |
+
methods = ['IMGS_bread', 'IMGS_iat', 'retinexformer_png', 'images', 'IMGS_Kind', 'IMGS_ZeroDCE', 'IMGS_nerco']
|
15 |
+
method_dict = {
|
16 |
+
'IMGS_bread': 'Bread',
|
17 |
+
'IMGS_iat': 'IAT',
|
18 |
+
'retinexformer_png': 'Retinexformer',
|
19 |
+
'images': 'Original Input',
|
20 |
+
'IMGS_Kind': 'Kind',
|
21 |
+
'IMGS_ZeroDCE': 'ZeroDCE',
|
22 |
+
'IMGS_nerco': 'NeRCo'
|
23 |
+
}
|
24 |
+
core_file = './file_list.txt'
|
25 |
+
bucket = os.getenv('bucket') #'https://checkpoints.mingjia.li/Exdark/'
|
26 |
+
image_list = []
|
27 |
+
with open(core_file, 'r') as f:
|
28 |
+
for line in f:
|
29 |
+
if line.strip().endswith('.png'):
|
30 |
+
image_list.append(line.strip())
|
31 |
+
|
32 |
+
from gradio.events import Dependency
|
33 |
+
|
34 |
+
class RandomState(gr.State):
|
35 |
+
def __init__(self, image, method1, method2, property):
|
36 |
+
super().__init__()
|
37 |
+
self.image = image
|
38 |
+
self.method1 = method1
|
39 |
+
self.method2 = method2
|
40 |
+
self.property = property
|
41 |
+
|
42 |
+
|
43 |
+
def compare_images(image1, image2):
|
44 |
+
return "Click on the better image."
|
45 |
+
with gr.Blocks() as block_demo:
|
46 |
+
|
47 |
+
def get_random_comparison():
|
48 |
+
import time
|
49 |
+
print(time.time())
|
50 |
+
random.seed(time.time())
|
51 |
+
image = random.choice(image_list)
|
52 |
+
method1, method2 = random.sample(methods, 2)
|
53 |
+
image1 = bucket + '/' + method1 + '/' + image
|
54 |
+
image2 = bucket + '/' + method2 + '/' + image
|
55 |
+
image_input = bucket + '/images/' + image
|
56 |
+
property = random.choice(all_property)
|
57 |
+
return image, method1, method2, image1, image2, property, image_input
|
58 |
+
|
59 |
+
def refresh_comparison():
|
60 |
+
return get_random_comparison()
|
61 |
+
def on_load(request: gr.Request):
|
62 |
+
headers = request.headers
|
63 |
+
host = request.client.host
|
64 |
+
request_state = dict(headers)
|
65 |
+
request_state['host'] = host
|
66 |
+
# print(str(request))
|
67 |
+
print(request_state)
|
68 |
+
image, method1, method2, image1, image2, property, image_input = refresh_comparison()
|
69 |
+
return image1, image2, f'### Which one is better in terms of **{property_dict[property]}**?',\
|
70 |
+
image, method1, method2, property, image_input, request_state
|
71 |
+
with gr.Row():
|
72 |
+
with gr.Column():
|
73 |
+
gr.Markdown("<h2 style='font-size: 24px;'>Low-light Image Enhancer Arena 🥊</h2>")
|
74 |
+
gr.Markdown("<p style='font-size: 18px;'>This is a simple arena to test the performance of different low-light image enhancers.</p>")
|
75 |
+
gr.Markdown("<p style='font-size: 18px;'>Please help us to find the better image!</p>")
|
76 |
+
gr.Markdown("<p style='font-size: 18px;'>Failures:</p>")
|
77 |
+
gr.Markdown("<ul style='font-size: 18px;'>"
|
78 |
+
f"<li><strong>Artifact:</strong> - There might be unwanted or unintended alterations in the image.</li>"
|
79 |
+
f"<li><strong>Color Degradation:</strong> - The color recoverd from low-light input is not the same as the color in the input image.</li>"
|
80 |
+
f"<li><strong>Noise:</strong> - There might be noise in the image.</li>"
|
81 |
+
f"<li><strong>Poor Illumination:</strong> - The brightness level of the image is not good, it might be too dark or too bright.</li>"
|
82 |
+
f"<li><strong>Blury:</strong> - The sharpness of the image is not good, it might be too blurry or too sharp.</li>"
|
83 |
+
"</ul>")
|
84 |
+
img_input = gr.Image(label="Input Image")
|
85 |
+
|
86 |
+
|
87 |
+
with gr.Row():
|
88 |
+
img1 = gr.Image(label="Image 1")
|
89 |
+
img2 = gr.Image(label="Image 2")
|
90 |
+
|
91 |
+
prop_text = gr.Markdown(f'###Which one is better in terms of x?')
|
92 |
+
image_state, method1_state, method2_state, property_state, ip_state = gr.State(), gr.State(), gr.State(), gr.State(), gr.State()
|
93 |
+
block_demo.load(on_load, inputs=[], outputs=[img1, img2, prop_text,
|
94 |
+
image_state, method1_state, method2_state, property_state, img_input, ip_state])
|
95 |
+
with gr.Row():
|
96 |
+
l_butt = gr.Button("Left is better")
|
97 |
+
r_butt = gr.Button("Right is better")
|
98 |
+
with gr.Row():
|
99 |
+
both_good = gr.Button("Both are good")
|
100 |
+
both_bad = gr.Button("Both are bad")
|
101 |
+
|
102 |
+
result = gr.Markdown("")
|
103 |
+
lnote, rnote = gr.Markdown(""), gr.Markdown("")
|
104 |
+
refresh_butt = gr.Button("Next one", visible=False, interactive=False)
|
105 |
+
# good, bad = gr.State('both_good'), gr.State('both_bad')
|
106 |
+
def update_interface(choice, image, method1, method2, property, ip):
|
107 |
+
# if type(choice) is not str : choice = choice.value
|
108 |
+
print(choice, image, method1, method2, property, ip)
|
109 |
+
send_message_to_mongodb(image, property, method1, method2, choice, ip)
|
110 |
+
# new_image, new_method1, new_method2, new_image1, new_image2, new_property = get_random_comparison()
|
111 |
+
return [
|
112 |
+
# gr.Markdown("### Thanks for your submission!"),
|
113 |
+
gr.Button(interactive=False),
|
114 |
+
gr.Button(interactive=False),
|
115 |
+
gr.Button(interactive=False),
|
116 |
+
gr.Button(interactive=False),
|
117 |
+
# gr.Markdown(f'Left image: {method_dict[method1]}'),
|
118 |
+
# gr.Markdown(f'Right image: {method_dict[method2]}'),
|
119 |
+
gr.Button(visible=True, interactive=True),
|
120 |
+
# gr.Image(new_image1),
|
121 |
+
# gr.Image(new_image2),
|
122 |
+
# f'### Submit your choice for **{new_property}**'
|
123 |
+
]
|
124 |
+
|
125 |
+
l_butt.click(fn=update_interface, inputs=[method1_state, image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
126 |
+
r_butt.click(fn=update_interface, inputs=[method2_state, image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
127 |
+
both_good.click(fn=update_interface, inputs=[gr.State('both_good'), image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
128 |
+
both_bad.click(fn=update_interface, inputs=[gr.State('both_bad'), image_state, method1_state, method2_state, property_state, ip_state], outputs=[l_butt, r_butt, both_good, both_bad, refresh_butt])
|
129 |
+
|
130 |
+
|
131 |
+
refresh_butt.click(None, js="window.location.reload()")
|
132 |
+
|
133 |
+
block_demo.launch()
|
db.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pymongo.mongo_client import MongoClient
|
2 |
+
from pymongo.server_api import ServerApi
|
3 |
+
import os
|
4 |
+
uri = os.getenv('db_uri')
|
5 |
+
|
6 |
+
# Create a new client and connect to the server
|
7 |
+
client = MongoClient(uri, server_api=ServerApi('1'))
|
8 |
+
|
9 |
+
|
10 |
+
def send_message_to_mongodb(filename, comparision, left_model, right_model, status, ip):
|
11 |
+
db = client.get_database("lime_eval")
|
12 |
+
collection = db.get_collection(f"{comparision}_comparisons")
|
13 |
+
|
14 |
+
message = {
|
15 |
+
"filename": filename,
|
16 |
+
"left_model": left_model,
|
17 |
+
"right_model": right_model,
|
18 |
+
"status": status,
|
19 |
+
"ip": ip
|
20 |
+
}
|
21 |
+
|
22 |
+
try:
|
23 |
+
collection.insert_one(message)
|
24 |
+
print("Message sent to MongoDB successfully.")
|
25 |
+
except Exception as e:
|
26 |
+
print(f"An error occurred while sending the message to MongoDB: {e}")
|
27 |
+
|
28 |
+
def get_all_messages_from_collection(comparision):
|
29 |
+
db = client.get_database("lime_eval")
|
30 |
+
collection = db.get_collection(f"{comparision}_comparisons")
|
31 |
+
|
32 |
+
try:
|
33 |
+
messages = list(collection.find())
|
34 |
+
if messages:
|
35 |
+
print("Messages retrieved from MongoDB successfully.")
|
36 |
+
return messages
|
37 |
+
else:
|
38 |
+
print("No messages found in the collection.")
|
39 |
+
return []
|
40 |
+
except Exception as e:
|
41 |
+
print(f"An error occurred while retrieving messages from MongoDB: {e}")
|
42 |
+
return []
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
send_message_to_mongodb("test.png", 'noise', "IMGS_bread", "IMGS_ZeroDCE", "IMGS_bread")
|
47 |
+
print(get_all_messages_from_collection('noise'))
|
file_list.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pymongo
|