File size: 1,825 Bytes
9b3729e
621f795
9b3729e
 
 
 
 
 
621f795
 
 
 
9b3729e
 
 
 
621f795
 
 
9b3729e
621f795
 
 
 
 
9b3729e
 
 
 
 
621f795
9b3729e
621f795
 
9b3729e
621f795
 
9b3729e
 
 
 
 
 
 
 
 
061df78
 
 
 
 
 
427379e
621f795
9b3729e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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