Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import cv2
|
| 5 |
+
import os
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import tensorflow as tf
|
| 8 |
+
import keras
|
| 9 |
+
import matplotlib
|
| 10 |
+
def dice_loss(y_true, y_pred):
|
| 11 |
+
smooth = 1.
|
| 12 |
+
y_true_f = K.flatten(y_true)
|
| 13 |
+
y_pred_f = K.flatten(y_pred)
|
| 14 |
+
intersection = y_true_f * y_pred_f
|
| 15 |
+
score = (2. * K.sum(intersection) + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
|
| 16 |
+
return 1. - score
|
| 17 |
+
from keras.models import load_model
|
| 18 |
+
model = load_model('model91.h5',custom_objects={'dice_loss':dice_loss})
|
| 19 |
+
def convert_sketch(img):
|
| 20 |
+
img = cv2.resize(img,(178,218))
|
| 21 |
+
img = img.astype(np.float32)/255.
|
| 22 |
+
y_pred = model.predict(img.reshape(1,218,178,3))
|
| 23 |
+
return(y_pred[0])
|
| 24 |
+
custom_text = "hello"
|
| 25 |
+
gr.Interface(fn=convert_sketch,inputs="image",outputs="image",title="Sketch To Image Converter",description="Warning: Upload the sketches of 178*218 pixels to get accurate results.").launch()
|