feng2022 commited on
Commit
40e259d
1 Parent(s): e910a5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -29,11 +29,11 @@ TOKEN = "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"
29
  pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
30
 
31
  def load_model(file_name: str, path:str,device: torch.device) -> nn.Module:
32
- path = hf_hub_download('hysts/StyleGAN-Human',
33
- f'models/{file_name}',
34
  use_auth_token=TOKEN)
35
  with open(path, 'rb') as f:
36
- model = pickle.load(f)['G_ema']
37
  model.eval()
38
  model.to(device)
39
  with torch.inference_mode():
@@ -44,12 +44,16 @@ def load_model(file_name: str, path:str,device: torch.device) -> nn.Module:
44
 
45
  def predict(text):
46
  return pipe(text)[0]["translation_text"]
47
-
48
- iface = gr.Interface(
49
- fn=predict,
50
- inputs='text',
51
- outputs='text',
52
- examples=[["Time-TravelRephotography"]]
53
- )
54
-
55
- iface.launch()
 
 
 
 
 
29
  pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
30
 
31
  def load_model(file_name: str, path:str,device: torch.device) -> nn.Module:
32
+ path = hf_hub_download(f'{path}',
33
+ f'{file_name}',
34
  use_auth_token=TOKEN)
35
  with open(path, 'rb') as f:
36
+ model = torch.load(f)
37
  model.eval()
38
  model.to(device)
39
  with torch.inference_mode():
 
44
 
45
  def predict(text):
46
  return pipe(text)[0]["translation_text"]
47
+
48
+ def main():
49
+ iface = gr.Interface(
50
+ fn=predict,
51
+ inputs='text',
52
+ outputs='text',
53
+ examples=[["Time-TravelRephotography"]]
54
+ )
55
+
56
+ iface.launch()
57
+
58
+ if __name__ == '__main__':
59
+ main()