feng2022 commited on
Commit
39868fe
1 Parent(s): be6a7ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -27,9 +27,23 @@ TOKEN = "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"
27
 
28
  pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def predict(text):
31
  return pipe(text)[0]["translation_text"]
32
-
33
  iface = gr.Interface(
34
  fn=predict,
35
  inputs='text',
 
27
 
28
  pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
29
 
30
+ def load_model(file_name: str, path:str,device: torch.device) -> nn.Module:
31
+ path = hf_hub_download('hysts/StyleGAN-Human',
32
+ f'models/{file_name}',
33
+ use_auth_token=TOKEN)
34
+ with open(path, 'rb') as f:
35
+ model = pickle.load(f)['G_ema']
36
+ model.eval()
37
+ model.to(device)
38
+ with torch.inference_mode():
39
+ z = torch.zeros((1, model.z_dim)).to(device)
40
+ label = torch.zeros([1, model.c_dim], device=device)
41
+ model(z, label, force_fp32=True)
42
+ return model
43
+
44
  def predict(text):
45
  return pipe(text)[0]["translation_text"]
46
+
47
  iface = gr.Interface(
48
  fn=predict,
49
  inputs='text',