import gradio as gr import numpy as np from transformers import pipeline from model import DepressionClassifier import hopsworks import joblib import torch from huggingface_hub import hf_hub_download class_names = ['Not Depressed', 'Depressed'] pt_file = hf_hub_download(repo_id="liangc40/sentimental_analysis", filename="model.pt") model = DepressionClassifier(len(class_names), 'bert-base-cased') model.load_state_dict(torch.load(pt_file, map_location=torch.device('cpu'))) model.eval() #pipe = pipeline(model="liangc40/sentimental_analysis") #project = hopsworks.login(project='liangc40') #fs = project.get_feature_store() #mr = project.get_model_registry() #model = mr.get_model("sentimental_analysis_model", version=1) #model_dir = model.download() #model = joblib.load(model_dir + "/sentimental_analysis_model.pkl") def analyse(text): label = model(text) return label with gr.Blocks() as demo: gr.Markdown("

Sentiment Analysis with Fine-tuned BERT Model") inputs_text=gr.Textbox(placeholder='Type your text for which you want know the sentiment', label='Text') text_button = gr.Button('Analyse Sentiment') output_text_sentiment = gr.Textbox(placeholder='Sentiment of the text.', label='Sentiment') text_button.click(analyse, inputs = inputs_text, outputs = output_text_sentiment) if __name__ == "__main__": demo.launch()