cv43 commited on
Commit
6f58148
·
1 Parent(s): d0dcb4e

initial commit

Browse files
Files changed (3) hide show
  1. app.py +0 -29
  2. model.py +0 -26
  3. requirements.txt +0 -6
app.py DELETED
@@ -1,29 +0,0 @@
1
- import gradio as gr
2
- import torch
3
- from model import Byt5LightningModule
4
-
5
- <<<<<<< HEAD
6
- <<<<<<< HEAD
7
- model = torch.load("model.pt", map_location=torch.device("cpu"), weights_only=True)
8
- =======
9
- model = torch.load("model.pt", map_location=torch.device("cpu"))
10
- >>>>>>> 4524122 (initial commit)
11
- =======
12
- model = torch.load("model.pt", map_location=torch.device("cpu"), weights_only=True)
13
- >>>>>>> 0efc206 (initial commit)
14
- model.eval()
15
-
16
- def predict(input_list):
17
- with torch.no_grad():
18
- tensor_input = torch.tensor([input_list], dtype=torch.float32)
19
- output = model(tensor_input).item()
20
- return f"Prediction: {output:.4f}"
21
-
22
- demo = gr.Interface(
23
- fn=predict,
24
- inputs=gr.Textbox(label="Input (Hex formatter Modbus request)"),
25
- outputs="text",
26
- examples=[["08090000000d001000250003060000ffffffff"]],
27
- )
28
-
29
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
model.py DELETED
@@ -1,26 +0,0 @@
1
- from lightning.pytorch import LightningModule
2
- from transformers import PreTrainedModel
3
-
4
-
5
- class Byt5LightningModule(LightningModule):
6
-
7
- def __init__(self, model: PreTrainedModel):
8
- super().__init__()
9
- self._model = model
10
-
11
- def forward(self, input_ids, attention_mask, decoder_attention_mask, labels=None):
12
- output = self.model(
13
- input_ids=input_ids,
14
- attention_mask=attention_mask,
15
- labels=labels,
16
- decoder_attention_mask=decoder_attention_mask,
17
- )
18
- return output.loss, output.logits
19
-
20
- @property
21
- def model(self):
22
- return self._model
23
-
24
- @property
25
- def tokenizer(self):
26
- return self._tokenizer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt DELETED
@@ -1,6 +0,0 @@
1
- lightning
2
- torch
3
- gradio
4
- transformers
5
- gradio
6
- transformers