Spaces:
Runtime error
Runtime error
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) | |
title_2 = "Symptoms and Disease" | |
description_2 = "Enter the Symptoms to know the disease" | |
# Input from user | |
in_prompt_2 = gradio.components.Textbox(lines=2, label='Enter the Symptoms') | |
# Output response | |
out_response_2 = gradio.components.Textbox(label='Disease') | |
# Gradio interface to generate UI link | |
iface_2 = gradio.Interface(fn=predict, | |
inputs = [in_prompt_2], | |
outputs = [out_response_2], | |
title=title_2, | |
description=description_2 | |
) | |
iface = gradio.Interface( | |
[ | |
iface_1, | |
iface_2 | |
], | |
title="Multiple Models Interface", | |
description="This interface showcases multiple models" | |
) | |
iface.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 |