IDubrovsky commited on
Commit
4746e24
1 Parent(s): 6e3296d

Add application file

Browse files
Files changed (3) hide show
  1. app.py +85 -0
  2. requirements.txt +4 -0
  3. xgb.ckpt +3 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+ from colormap import rgb2hex
5
+ from PIL import Image
6
+
7
+ def predict(m_cloth, v_w, v_m, v_k, v_b, m_al, m_cu, m_fe, m_tan, time, pH):
8
+ xgb = pickle.load(open('xgb.ckpt', 'rb'))
9
+ v_sum = v_w + v_m + v_k + v_b
10
+ 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])
11
+ y = xgb.predict(X)
12
+ r, g, b = y[0]
13
+ img = Image.new('RGB',(200,200),(int(r),int(g),int(b)))
14
+ hex_color = rgb2hex(int(r), int(g), int(b))
15
+ return hex_color, int(r), int(g), int(b), hex_color, img
16
+
17
+ with gr.Blocks() as demo:
18
+ with gr.Column():
19
+ gr.Markdown(
20
+ """
21
+ # Predicting the conditions of dyeing of cotton fabric with natural dyes to obtain a given color
22
+ """)
23
+ with gr.Row():
24
+ with gr.Column(scale=4):
25
+ gr.Markdown(
26
+ """
27
+ 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.
28
+
29
+ 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**.
30
+
31
+ Dataset, code and detailed slides: **TBA**.
32
+
33
+ Limitations of the algorithm's performance:
34
+
35
+
36
+ * Limited palette of colors for which high prediction accuracy is preserved (see *Figure 1*)
37
+ * 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)
38
+ * As in many machine learning models, borderline values with less data are predicted worse (e.g. in the case of very dilute solutions)
39
+
40
+ Authors:
41
+ Ekaterina Veselyaeva \*,
42
+ Alisa Pigulevskaya \*,
43
+ Sofia Ryakhovskaya \*.
44
+
45
+ Supervisor:
46
+ Ivan Dubrovsky \*\*.
47
+
48
+ \* Lyceum № 226, St. Petersburg
49
+
50
+ \*\* Artificial Intelligence in Chemistry Center, ITMO University, St. Petersburg
51
+ """)
52
+ with gr.Column(scale=3):
53
+ gr.Image("https://drive.usercontent.google.com/u/1/uc?id=1Bokju7A-owxh3cc3C623YqmAqKSSrdtO&export=download", height = 500, width = 500)
54
+ gr.Markdown("""
55
+ *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).*
56
+ """)
57
+ with gr.Row():
58
+ with gr.Column(scale=4):
59
+ inp= [gr.Number(label = 'Weight of fabric, g', minimum = 0, maximum = 1000, value = 0.1),
60
+ gr.Number(label = 'Water volume, ml', minimum = 0, maximum = 1000, value = 5),
61
+ gr.Number(label = 'Volume of madder dye solution, ml', minimum = 0, maximum = 1000, value = 5),
62
+ gr.Number(label = 'Volume of turmeric dye solution, ml', minimum = 0, maximum = 1000, value = 5),
63
+ gr.Number(label = 'Volume of elderberry dye solution, ml', minimum = 0, maximum = 1000),
64
+ gr.Number(label = 'Weight of added aluminum salt, g', minimum = 0, maximum = 1000),
65
+ gr.Number(label = 'Weight of added copper salt, g', minimum = 0, maximum = 1000),
66
+ gr.Number(label = 'Weight of added iron salt, g', minimum = 0, maximum = 1000),
67
+ gr.Number(label = 'Weight of added tannin, g', minimum = 0, maximum = 1000),
68
+ gr.Number(label = 'Dyeing time, min', minimum = 0, maximum = 5000, value = 60),
69
+ gr.Number(label = 'pH', minimum = 0, maximum = 14, value = 6)]
70
+ with gr.Column(scale=3):
71
+ out = [gr.ColorPicker(label="Color"),
72
+ gr.Number(label = 'R', minimum = 0, maximum = 255),
73
+ gr.Number(label = 'G', minimum = 0, maximum = 255),
74
+ gr.Number(label = 'B', minimum = 0, maximum = 255),
75
+ gr.Textbox(label="Hexadecimal color"),
76
+ gr.Image(label="Color image", height = 500, width = 500)]
77
+ button = gr.Button()
78
+ button.click(fn=predict, inputs=inp, outputs=out)
79
+ demo.launch()
80
+
81
+ def greet(name):
82
+ return "Hello " + name + "!!"
83
+
84
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
85
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ colormap
2
+ pandas
3
+ xgboost
4
+ PIL
xgb.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8171793ff02c45d048efd553b92879dd2946bad67cc914f2c62a336658868c95
3
+ size 342046