Commit
·
322922b
1
Parent(s):
ef82efc
added anther model
Browse files
app.py
CHANGED
|
@@ -1,35 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import tensorflow as tf
|
| 4 |
-
from transformers import AutoTokenizer
|
| 5 |
-
from model import SentimentClassifier
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
model.load_state_dict(model_state_dict)
|
| 10 |
-
model.eval()
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
inputs = tokenizer(text, padding='max_length',
|
| 17 |
-
truncation=True, max_length=512, return_tensors='pt')
|
| 18 |
-
return inputs
|
| 19 |
-
# Define a function to use the model to make predictions
|
| 20 |
-
def predict(review):
|
| 21 |
-
inputs = preprocess(review)
|
| 22 |
-
with torch.no_grad():
|
| 23 |
-
outputs = model(inputs['input_ids'], inputs['attention_mask'])
|
| 24 |
-
predicted_class = torch.argmax(outputs[0]).item()
|
| 25 |
-
if(predicted_class==0):
|
| 26 |
-
return "It was a negative review"
|
| 27 |
-
return "It was a positive review"
|
| 28 |
|
| 29 |
-
|
| 30 |
-
input_text = gr.inputs.Textbox(label="Input Text")
|
| 31 |
-
output_text = gr.outputs.Textbox(label="Output Text")
|
| 32 |
-
interface = gr.Interface(fn=predict, inputs=input_text, outputs=output_text)
|
| 33 |
-
|
| 34 |
-
# Run the interface
|
| 35 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load the model
|
| 5 |
+
learn = load_learner('sentimentality.h5')
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Prediction function
|
| 8 |
+
def make_prediction(user_sentence):
|
| 9 |
+
|
| 10 |
+
prediction = learn.predict(user_sentence)
|
| 11 |
+
dict = {'1': 'Negative', '2': 'Neutral', '3': 'Positive'}
|
| 12 |
+
return dict[prediction[0]]
|
| 13 |
|
| 14 |
+
title = "Sentiment Analysis MyAnimeList Reviews with fastai"
|
| 15 |
+
description = "<p style='text-align: center'>Identifier si un commentaire dans MyAnimeList est positif, neutre ou négatif.<br/> Permet de connaître rapidement le sentiment globale que dégage un avis sur le site.</p>"
|
| 16 |
|
| 17 |
+
app = gr.Interface(fn=make_prediction, title=title, description=description, inputs=gr.TextArea(), outputs='text')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|