Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from torchtext.data.utils import get_tokenizer
|
4 |
+
from torchtext.vocab import build_vocab_from_iterator
|
5 |
+
from torchtext.datasets import Multi30k
|
6 |
+
from torch import Tensor
|
7 |
+
from typing import Iterable, List
|
8 |
+
|
9 |
+
from germanToEnglish import Seq2SeqTransformer, translate
|
10 |
+
|
11 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
12 |
+
model = model.load_state_dict(torch.load('./transformer_model.pth', map_location=device))
|
13 |
+
model.eval()
|
14 |
+
|
15 |
+
if __name__ == "__main__":
|
16 |
+
# Create the Gradio interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=translate, # Specify the translation function as the main function
|
19 |
+
inputs=[
|
20 |
+
gr.inputs.Textbox(label="Text")
|
21 |
+
|
22 |
+
],
|
23 |
+
outputs=["text"], # Define the output type as text
|
24 |
+
cache_examples=False, # Disable caching of examples
|
25 |
+
title="germanToenglish", # Set the title of the interface
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the interface
|
29 |
+
iface.launch(share=True)
|