Spaces:
Runtime error
Runtime error
import gradio as gr | |
import hopsworks | |
import requests | |
import joblib | |
import pandas as pd | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
project = hopsworks.login(api_key_value ="sQdPNNOE9nnZ3WRE.TZlTI9jTPrrCAWr0NIYZUJimLfikNcSS40lAVp2uQC2lEQRHEaQSBSZgh5EuowHm") | |
fs = project.get_feature_store() | |
mr = project.get_model_registry() | |
model = mr.get_model("twi_model_new", version=2) | |
model_dir = model.download() | |
model = joblib.load(model_dir + "/twi_model.pkl") | |
vectoriser = joblib.load(model_dir+'/tfidf_vectoriser.joblib') | |
print("Model downloaded") | |
# text="good" | |
# text=pd.DataFrame([text], columns=['text']) | |
# vectoriser = TfidfVectorizer(ngram_range=(1,2), max_features=500000) | |
# vectoriser.fit(text) | |
# text=vectoriser.transform(text) | |
# print(type(text)) | |
def predict_sentiment(text): | |
input = [text] | |
print(input) | |
# text=text.tolist() | |
input = vectoriser.transform(input) | |
res = model.predict(input) | |
if (res==1): | |
sentiment_url="https://files.selecthealth.cloud/api/public/content/228422-being_positive_blog_lg.jpg" | |
else : | |
sentiment_url="https://mentalhealthatease.com/wp-content/uploads/2022/02/girl-with-negative-thoughts-scaled.jpeg" | |
img = Image.open(requests.get(sentiment_url, stream=True).raw) | |
return img | |
iface = gr.Interface( | |
fn=predict_sentiment, | |
inputs=gr.Textbox(), | |
outputs=gr.Image(type = 'pil'), | |
allow_flagging="never", | |
title="Tweet Sentiment Predict", | |
description="Input your tweet text to predict the sentiment" | |
) | |
iface.launch() |