IDubrovsky's picture
final
27db21d
import gradio as gr
import pickle
import pandas as pd
from colormap import rgb2hex
from PIL import Image
def predict(m_cloth, v_w, v_m, v_k, v_b, m_al, m_cu, m_fe, m_tan, time, pH):
xgb = pickle.load(open('xgb.ckpt', 'rb'))
v_sum = v_w + v_m + v_k + v_b
X = pd.DataFrame({'m_cloth': m_cloth, 'v_w': v_w / v_sum, 'v_m': v_m / v_sum, 'v_k': v_k / v_sum, 'v_b': v_b / v_sum, 'm_al': m_al, 'm_cu': m_cu, 'm_fe': m_fe, 'm_tan': m_tan, 'time': time, 'pH': pH}, index = [0])
y = xgb.predict(X)
r, g, b = y[0]
img = Image.new('RGB',(200,200),(int(r),int(g),int(b)))
hex_color = rgb2hex(int(r), int(g), int(b))
return hex_color, int(r), int(g), int(b), hex_color, img
with gr.Blocks() as demo:
with gr.Column():
gr.Markdown(
"""
# Predicting the conditions of dyeing of cotton fabric with natural dyes to obtain a given color
""")
with gr.Row():
with gr.Column(scale=4):
gr.Markdown(
"""
This service was created as part of the project **"Predicting the conditions of dyeing of cotton fabric with natural dyes to obtain a given color"** under the **Sirius.Leto** program. The purpose of this service is to determine in advance the result of dyeing the fabric with natural dyes, without conducting experiments. This is achieved by using the **Extreme Gradient Boosting Regressor** model, which allows to predict the color in **RGB** format based on the initial dyeing parameters.
To build this model, **240** fabric dyeing experiments were conducted at **ITMO University**. These experiments formed the dataset on which the models were built with **R<sup>2</sup> = 0.82** on the test set. Additionally, **8** experiments close but different from the experiments in the original dataset were performed, on which the algorithm was validated. The accuracy on the validation set was **R<sup>2</sup> = 0.88**.
Dataset, code and detailed slides: **TBA**.
Limitations of the algorithm's performance:
* Limited palette of colors for which high prediction accuracy is preserved (see *Figure 1*)
* Limited investigation of the influence of additional factors such as additives, pH, temperature (many of these parameters are less likely to determine the final color)
* As in many machine learning models, borderline values with less data are predicted worse (e.g. in the case of very dilute solutions)
Authors:
Ekaterina Veselyaeva \*,
Alisa Pigulevskaya \*,
Sofia Ryakhovskaya \*.
Supervisor:
Ivan Dubrovsky \*\*.
\* Lyceum № 226, St. Petersburg
\*\* Artificial Intelligence in Chemistry Center, ITMO University, St. Petersburg
""")
with gr.Column(scale=3):
gr.Image("https://drive.usercontent.google.com/u/1/uc?id=1Bokju7A-owxh3cc3C623YqmAqKSSrdtO&export=download", height = 500, width = 500)
gr.Markdown("""
*Figure 1. A palette of colors that the algorithm is able to predict with high accuracy (mostly the colors of the original dyes and their combinations).*
""")
with gr.Row():
with gr.Column(scale=4):
inp= [gr.Number(label = 'Weight of fabric, g', minimum = 0, maximum = 1000, value = 0.1),
gr.Number(label = 'Water volume, ml', minimum = 0, maximum = 1000, value = 5),
gr.Number(label = 'Volume of madder dye solution, ml', minimum = 0, maximum = 1000, value = 5),
gr.Number(label = 'Volume of turmeric dye solution, ml', minimum = 0, maximum = 1000, value = 5),
gr.Number(label = 'Volume of elderberry dye solution, ml', minimum = 0, maximum = 1000),
gr.Number(label = 'Weight of added aluminum salt, g', minimum = 0, maximum = 1000),
gr.Number(label = 'Weight of added copper salt, g', minimum = 0, maximum = 1000),
gr.Number(label = 'Weight of added iron salt, g', minimum = 0, maximum = 1000),
gr.Number(label = 'Weight of added tannin, g', minimum = 0, maximum = 1000),
gr.Number(label = 'Dyeing time, min', minimum = 0, maximum = 5000, value = 60),
gr.Number(label = 'pH', minimum = 0, maximum = 14, value = 6)]
with gr.Column(scale=3):
out = [gr.ColorPicker(label="Color"),
gr.Number(label = 'R', minimum = 0, maximum = 255),
gr.Number(label = 'G', minimum = 0, maximum = 255),
gr.Number(label = 'B', minimum = 0, maximum = 255),
gr.Textbox(label="Hexadecimal color"),
gr.Image(label="Color image", height = 500, width = 500)]
button = gr.Button()
button.click(fn=predict, inputs=inp, outputs=out)
demo.launch()