File size: 1,385 Bytes
4157a5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcb0fa8
4157a5f
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
#!/usr/bin/env python
# coding: utf-8

# In[13]:


#Model train
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn import metrics

dataset=pd.read_excel('Final_project.xlsx')
model=SVC(C=1000, gamma=1,kernel='rbf')

X=dataset[['%R','%G','%B']].values
y=dataset[['Condition']].values

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.20)
model.fit(X_train,y_train)
y_pred=model.predict(X_test)
metrics.accuracy_score(y_pred,y_test)


# In[14]:



#Web app code

import gradio as gr
import numpy as np
import cv2
def classification(image):
    
   
    #%RGB extraction 
    
    i=image.shape[0]
    j=image.shape[1]
    a=[];b=[];c=[]
    for x in range (0,j,1):
        for y in range(0,i,1):
            color = image[y,x]
            a.append(color[0])
            b.append(color[1])
            c.append(color[2])

    r=np.sum(a)
    g=np.sum(b)
    b=np.sum(c)
    R_percent=(r/(r+g+b))*100
    G_percent=(g/(r+g+b))*100
    B_percent=(b/(r+g+b))*100
    t= [[R_percent, G_percent,B_percent]]
    
   #Prediction

    s=model.predict(t)
    l=s.tolist()
    return ''.join(l)
    
    
   
   #GUI generation 

gr.Interface(fn=classification,inputs=[gr.inputs.Image(label="Upload your cropped image of fingernail")], outputs=[gr.outputs.Textbox(label="Condition")],title='Anemia Prediction').launch()