Spaces:
Runtime error
Runtime error
Dawid Motyka
commited on
Commit
·
f5d4fa9
1
Parent(s):
834d42f
add token
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
import numpy as np
|
@@ -10,7 +11,7 @@ from models import StanceEncoderModel
|
|
10 |
CLASS_DICT = {0: 'FAVOR', 1: 'AGAINST', 2: 'NEITHER'}
|
11 |
|
12 |
params = {'lang': 'pl',
|
13 |
-
'masked_lm_prompt': 4,}
|
14 |
|
15 |
|
16 |
class StancePipeline(Pipeline):
|
@@ -19,7 +20,8 @@ class StancePipeline(Pipeline):
|
|
19 |
return pipeline_parameters, {}, {}
|
20 |
|
21 |
def preprocess(self, input):
|
22 |
-
prompt_text, prompt_target = prepare_stance_texts([input['text'],], [input['target'],], params,
|
|
|
23 |
inputs = self.tokenizer(prompt_text, prompt_target, return_tensors="pt", padding=True, truncation='only_first')
|
24 |
return {'input_ids': inputs['input_ids'], 'attention_mask': inputs['attention_mask'],
|
25 |
'sequence_ids': torch.tensor((np.array(inputs.sequence_ids()) == 1).astype(int)).unsqueeze(0)}
|
@@ -34,9 +36,11 @@ class StancePipeline(Pipeline):
|
|
34 |
return {'stance': CLASS_DICT[probas.argmax(-1).item()], 'score': score}
|
35 |
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
|
41 |
|
42 |
def predict(text, target):
|
@@ -53,4 +57,4 @@ gradio_app = gr.Interface(
|
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
-
gradio_app.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
|
4 |
import numpy as np
|
|
|
11 |
CLASS_DICT = {0: 'FAVOR', 1: 'AGAINST', 2: 'NEITHER'}
|
12 |
|
13 |
params = {'lang': 'pl',
|
14 |
+
'masked_lm_prompt': 4, }
|
15 |
|
16 |
|
17 |
class StancePipeline(Pipeline):
|
|
|
20 |
return pipeline_parameters, {}, {}
|
21 |
|
22 |
def preprocess(self, input):
|
23 |
+
prompt_text, prompt_target = prepare_stance_texts([input['text'], ], [input['target'], ], params,
|
24 |
+
self.tokenizer)
|
25 |
inputs = self.tokenizer(prompt_text, prompt_target, return_tensors="pt", padding=True, truncation='only_first')
|
26 |
return {'input_ids': inputs['input_ids'], 'attention_mask': inputs['attention_mask'],
|
27 |
'sequence_ids': torch.tensor((np.array(inputs.sequence_ids()) == 1).astype(int)).unsqueeze(0)}
|
|
|
36 |
return {'stance': CLASS_DICT[probas.argmax(-1).item()], 'score': score}
|
37 |
|
38 |
|
39 |
+
model = StanceEncoderModel.from_pretrained('clarin-knext/stance-pl-1',
|
40 |
+
use_auth_token=os.environ['TOKEN'])
|
41 |
+
tokenizer = AutoTokenizer.from_pretrained('clarin-knext/stance-pl-1',
|
42 |
+
use_auth_token=os.environ['TOKEN'])
|
43 |
+
pipeline = StancePipeline(model=model, tokenizer=tokenizer, batch_size=1)
|
44 |
|
45 |
|
46 |
def predict(text, target):
|
|
|
57 |
)
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
+
gradio_app.launch()
|