runaksh's picture
Update app.py
061df78
raw
history blame
1.83 kB
import os
import gradio
from PIL import Image
from timeit import default_timer as timer
from tensorflow import keras
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import numpy as np
username = "runaksh"
repo_name = "finetuned-sentiment-model"
repo_path = username+ '/' + repo_name
model_1 = pipeline(model= repo_path)
model_2 = AutoModelForSequenceClassification.from_pretrained("runaksh/Symptom-2-disease_distilBERT")
tokenizer_2 = AutoTokenizer.from_pretrained("runaksh/Symptom-2-disease_distilBERT")
# Function for response generation
def predict_sentiment(text):
result = model_1(text)
if result[0]['label'].endswith('0'):
return 'Negative'
else:
return 'Positive'
def predict(sample, validate=True):
classifier = pipeline("text-classification", model=model_2, tokenizer=tokenizer_2)
pred = classifier(sample)[0]['label']
return pred
# Input from user
in_prompt_1 = gradio.components.Textbox(lines=10, placeholder=None, label='Enter review text')
# Output response
out_response_1 = gradio.components.Textbox(type="text", label='Sentiment')
# Gradio interface to generate UI link
title_1 = "Sentiment Classification"
description_1 = "Analyse sentiment of the given review"
iface_1 = gradio.Interface(fn = predict_sentiment,
inputs = [in_prompt_1],
outputs = [out_response_1],
title = title_1,
description = description_1)
iface = gradio.Interface(
iface_1,
title="Multiple Models Interface",
description="This interface showcases multiple models"
)
iface_1.launch(debug = True)
#iface.launch(debug = True)#, server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface