File size: 1,213 Bytes
cb70b4c
249653c
3eeeced
48b3a1c
249653c
3eeeced
 
 
 
fffc3a2
8503f33
3eeeced
115b639
 
 
 
 
 
 
d52eb29
115b639
 
fffc3a2
3eeeced
 
 
fffc3a2
115b639
 
 
 
 
 
 
 
 
 
 
fffc3a2
5264799
cb70b4c
1f780c8
 
fffc3a2
 
cb70b4c
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 gradio as gr
import requests
import torch
import torch.nn as nn

import timm

model = timm.create_model("hf_hub:nateraw/resnet18-random", pretrained=True)
model.train()

import os 

def print_bn():
    bn_data = []
    for m in model.modules():
        if(type(m) is nn.BatchNorm2d):
            # print(m.momentum)
            bn_data.extend(m.running_mean.data.numpy().tolist())
            bn_data.extend(m.running_var.data.numpy().tolist())
            bn_data.append(m.momentum)
    return bn_data

def greet(image):
    # url = f'https://huggingface.co/spaces?p=1&sort=modified&search=GPT'
    # html = request_url(url)
    # key = os.getenv("OPENAI_API_KEY")
#     x = torch.ones([1,3,224,224])
    if(image is None):
        print_bn()
    else:
        print(type(image))
        image = torch.tensor(image).float()
        print(image.min(), image.max())
        image = image/255.0
        image = image.unsqueeze(0)
        image = torch.permute(image, [0,2,3,1])
        out = model(image)

    # model.train()
    return "Hello world!"



image = gr.inputs.Image(label="Upload a photo for beautify", shape=(224,224))
iface = gr.Interface(fn=greet, inputs=image, outputs="text")
iface.launch()