Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import numpy as np
|
| 3 |
from model import Transformer
|
|
@@ -33,21 +34,20 @@ m = model.to(DEVICE)
|
|
| 33 |
m = torch.load("base_mode.pth", map_location=torch.device(DEVICE))
|
| 34 |
m.eval()
|
| 35 |
|
| 36 |
-
print(
|
| 37 |
-
"Model with {:.2f}M parameters".format(sum(p.numel() for p in m.parameters()) / 1e6)
|
| 38 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
#context = torch.zeros((1, 1), dtype=torch.long, device=DEVICE)
|
| 43 |
-
text_input = str(input())
|
| 44 |
-
context_np = np.array(encode(text_input, tokenizer))
|
| 45 |
-
context_np = np.array([context_np])
|
| 46 |
-
context = torch.from_numpy(context_np)
|
| 47 |
-
print(context)
|
| 48 |
-
print(
|
| 49 |
-
decode(
|
| 50 |
-
enc_sec=m.generate(idx=context, max_new_tokens=100, block_size=BLOCK_SIZE)[0],
|
| 51 |
-
tokenizer=tokenizer,
|
| 52 |
-
)
|
| 53 |
-
)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
from model import Transformer
|
|
|
|
| 34 |
m = torch.load("base_mode.pth", map_location=torch.device(DEVICE))
|
| 35 |
m.eval()
|
| 36 |
|
| 37 |
+
#print(
|
| 38 |
+
# "Model with {:.2f}M parameters".format(sum(p.numel() for p in m.parameters()) / 1e6)
|
| 39 |
+
#)
|
| 40 |
+
def model_generate(text):
|
| 41 |
+
# generate some output based on the context
|
| 42 |
+
#context = torch.tensor(np.array(encode("Hello! My name is ", tokenizer)))
|
| 43 |
+
#context = torch.zeros((1, 1), dtype=torch.long, device=DEVICE)
|
| 44 |
+
text_input = str(input())
|
| 45 |
+
context_np = np.array(encode(text_input, tokenizer))
|
| 46 |
+
context_np = np.array([context_np])
|
| 47 |
+
context = torch.from_numpy(context_np)
|
| 48 |
+
#print(context)
|
| 49 |
+
|
| 50 |
+
return decode(enc_sec=m.generate(idx=context, max_new_tokens=100, block_size=BLOCK_SIZE)[0], tokenizer=tokenizer)
|
| 51 |
|
| 52 |
+
iface = gr.Interface(fn=model_generate, inputs="text", outputs="text")
|
| 53 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|