Sambhavnoobcoder commited on
Commit
84accd9
·
1 Parent(s): df4a4f8

adapted demo model a little more

Browse files
Files changed (1) hide show
  1. app.py +1 -32
app.py CHANGED
@@ -1,34 +1,3 @@
1
  import gradio as gr
2
- import torch
3
- from transformers import AutoTokenizer
4
- from model import SentimentClassifier
5
 
6
- model_state_dict = torch.load('sentimentality.h5')
7
- model = SentimentClassifier(2)
8
- model.load_state_dict(model_state_dict)
9
- model.eval()
10
-
11
- tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
12
-
13
-
14
- def preprocess(text):
15
- inputs = tokenizer(text, padding='max_length',
16
- truncation=True, max_length=512, return_tensors='pt')
17
- return inputs
18
- # Define a function to use the model to make predictions
19
- def predict(review):
20
- inputs = preprocess(review)
21
- with torch.no_grad():
22
- outputs = model(inputs['input_ids'], inputs['attention_mask'])
23
- predicted_class = torch.argmax(outputs[0]).item()
24
- if(predicted_class==0):
25
- return "It was a negative review"
26
- return "It was a positive review"
27
-
28
- # Create a Gradio interface
29
- input_text = gr.inputs.Textbox(label="Input Text")
30
- output_text = gr.outputs.Textbox(label="Output Text")
31
- interface = gr.Interface(fn=predict, inputs=input_text, outputs=output_text)
32
-
33
- # Run the interface
34
- interface.launch()
 
1
  import gradio as gr
 
 
 
2
 
3
+ gr.Interface.load("models/finiteautomata/bertweet-base-sentiment-analysis",interpretation="default").launch()