File size: 1,282 Bytes
11d38b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import tensorflow.lite as tfl
import matplotlib.pyplot as plt
import gradio as gr
import torchvision.utils as vutils
import torch
print("imported stuff")
interpreter = tfl.Interpreter(model_path="resnet.tflite")
interpreter.allocate_tensors()
print('started up model')
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

input_shape = input_details[0]['shape']

def makemon():
  input_data = np.array(np.random.normal(size=input_shape), dtype=np.float32)
  interpreter.set_tensor(input_details[0]['index'], input_data)
  
  interpreter.invoke()
  
  output_data = interpreter.get_tensor(output_details[0]['index'])
  
  grid = vutils.make_grid(torch.from_numpy(output_data).detach().cpu(), padding=0, normalize=True)
  
  first_image = grid[:, :grid.size(1) // 8, :grid.size(2) // 8]  # Assuming an 8x8 grid
  
  plt.figure(figsize=(7, 7))
  plt.imshow(np.transpose(first_image.numpy(), (1, 2, 0)))
  mon = plt.axis('off')  # Turn off axis for a cleaner look
  return plt.gcf()
a = makemon()
print("mademon")
demo = gr.Interface(
    makemon,
    [
    ],
    outputs = gr.Plot(label="Pokemon", format="png"),
)

if __name__ == "__main__":
    demo.launch(debug=True)