jiang20 commited on
Commit
bf50f54
·
1 Parent(s): 9651869

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import torch
4
+ import torch.nn as nn
5
+
6
+ import timm
7
+
8
+ model = timm.create_model("hf_hub:nateraw/resnet18-random", pretrained=True)
9
+ model.train()
10
+
11
+ import os
12
+
13
+ def print_bn():
14
+ bn_data = []
15
+ for m in model.modules():
16
+ if(type(m) is nn.BatchNorm2d):
17
+ # print(m.momentum)
18
+ bn_data.extend(m.running_mean.data.numpy().tolist())
19
+ bn_data.extend(m.running_var.data.numpy().tolist())
20
+ bn_data.append(m.momentum)
21
+ return bn_data
22
+
23
+ def greet(image):
24
+ # url = f'https://huggingface.co/spaces?p=1&sort=modified&search=GPT'
25
+ # html = request_url(url)
26
+ # key = os.getenv("OPENAI_API_KEY")
27
+ # x = torch.ones([1,3,224,224])
28
+ if(image is None):
29
+ bn_data = print_bn()
30
+ return ','.join([f'{x:.10f}' for x in bn_data])
31
+ else:
32
+ print(type(image))
33
+ image = torch.tensor(image).float()
34
+ print(image.min(), image.max())
35
+ image = image/255.0
36
+ image = image.unsqueeze(0)
37
+ print(image.shape)
38
+ image = torch.permute(image, [0,3,1,2])
39
+ out = model(image)
40
+
41
+ # model.train()
42
+ return "Hello world!"
43
+
44
+
45
+
46
+ image = gr.inputs.Image(label="Upload a photo for beautify", shape=(224,224))
47
+ iface = gr.Interface(fn=greet, inputs=image, outputs="text")
48
+ iface.launch()