Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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('
|
33 |
-
f'
|
34 |
use_auth_token=TOKEN)
|
35 |
with open(path, 'rb') as f:
|
36 |
-
model =
|
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 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
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()
|