KLeedrug's picture
Hope this works!
4aee7bd
# -*- coding: utf-8 -*-
"""GRADIO_2.ipynb
"""
import tensorflow as tf
from keras.models import Sequential, save_model
from keras.layers import Dense,Dropout,Flatten,Conv2D,MaxPooling2D, Conv1D, Reshape, BatchNormalization, Add
import os
#os.system("unzip 98percentmodel-20220909T223547Z-001.zip")
os.system("unzip 9826model-20220910T034210Z-001.zip")
import keras
#new_model = keras.models.load_model('98percentmodel')
new_model = keras.models.load_model('9826model')
import numpy as np
import gradio as gr
"""# Go with this"""
"define our function"
"""
import numpy as np
xt = np.array([[1,2],[3,4],[5,6], [7,8]])
yt = np.array([[1,2],[3,4],[5,6]])
"""
#def get_output(inp, model=new_model):
# works!
def get_output(inp_0, inp_1, inp_2, inp_3, inp_4, inp_5, inp_6, inp_7): #, model=new_model):
# inp: 8 floats
# cast into [[float,float]...]
inp = [inp_0, inp_1, inp_2, inp_3, inp_4, inp_5, inp_6, inp_7]
ii = []
for idx in range(0,len(inp),2):
ii.append([inp[idx], inp[idx+1]])
assert len(ii) == 4
inp = np.array(ii)
inp = np.array(inp)
inp = np.array(inp).reshape((1,4,2,1))
real_inp = np.array([inp]).reshape((1,4,2,1))
out = new_model.predict(real_inp)
# cast to float
ret = []
for ele in out[0]:
ret.append(list(map(float, ele)))
#return ret
rr = [x for y in ret for x in y]
return rr[0], rr[1], rr[2], rr[3], rr[4], rr[5]
interface = gr.Interface(
fn = get_output,
#inputs=[["number", "number"],["number", "number"],["number", "number"],["number", "number"]],
#inputs = [["number","number","number","number","number","number","number", "number"]],
inputs = ["number","number","number","number","number","number","number", "number"],
#outputs=["number"]
#outputs = "number"
outputs = ["number","number","number","number","number","number"]
)
interface.launch()