Spaces:
Runtime error
Runtime error
File size: 1,901 Bytes
9761446 5943c14 c6ebbf7 5943c14 c6ebbf7 8e74776 3c40e92 3d9f2aa c6ebbf7 c028611 c6ebbf7 3d9f2aa c6ebbf7 3c40e92 c028611 ae75f7c 9affe57 ae75f7c 9affe57 ae75f7c ec1a796 c6ebbf7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
from sentiment_wrapper import PredictionModel
import gradio as gr
model = PredictionModel()
def predict(text:str):
result = model.predict([text])[0]
return f'class: {result}'
markdown_text = '''
<br>
<br>
This space provides a gradio demo and an easy-to-run wrapper of the pre-trained model for fine-grained sentiment analysis in Norwegian language, pre-trained on the NoReC dataset.
Information about project you an fine on the website of [University of Oslo](https://www.mn.uio.no/ifi/english/research/projects/sant/)
## How to do inference?
Specify in config.json which model from saved_models you want to use. The model can be easily used for predicting sentiment as follows:
```python
>>> from sentiment_wrapper import PredictionModel
>>> model = PredictionModel()
>>> model.predict(['vi liker svart kaffe', 'jeg elsker virkelig røde roser!'])
[5,5]
```
## How to fine-tune?
For this run fine-tune.py and specify required arguments:
<ul>
<li>-dataframe: pandas dataframe with columns ['text', 'label', 'split'] with 3 possible values in 'split' ['train','dev','test']</li>
<li>-model: pre-traied model from huggingface or path to local folder with config.json in case you want to use custom wrapper</li>
</ul>
If you want to use custom wrapper, please specify:
-custom_wrapper = True
<ul>
<li>-custom_wrapper = True</li>
</ul>
There are also additional arguments possible but not required:
<ul>
<li>-lr</li>
<li>-max_length</li>
<li>-warmup</li>
<li>-epochs</li>
</ul>
'''
with gr.Blocks() as demo:
with gr.Row(equal_height=False) as row:
text_input = gr.Textbox(label="input")
text_output = gr.Textbox(label="output")
with gr.Row(scale=4) as row:
text_button = gr.Button("submit").style(full_width=True)
text_button.click(fn=predict, inputs=text_input, outputs=text_output)
gr.Markdown(markdown_text)
demo.launch()
|