Spaces:
Runtime error
Runtime error
#!/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() | |