File size: 715 Bytes
dfaf21a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import hf_hub_download

from fineTuning import RoBERTaModule

MODEL_REPO_ID = "DornierDo17/MiniRoBERTa_SST2"
WEIGHTS_FILE = "finetuned.pt"

weight_path = hf_hub_download(repo_id=MODEL_REPO_ID, filename=WEIGHTS_FILE)


module = RoBERTaModule()
module.load_checkpoint(path=weight_path, location="cpu")


def predict(sentence):
    result = module.inference(sentence)
    return result


gr.Interface(
    fn=predict,
    inputs=gr.Textbox(
        label="Enter a piece of the review",
        placeholder="Example: I liked that part of film!",
    ),
    outputs=gr.Textbox(label="Predicted outcome: 0 - negative, 1 - positive "),
    title="Review classfication",
).launch()