File size: 2,443 Bytes
9b3729e
621f795
9b3729e
 
 
 
 
 
621f795
 
 
 
9b3729e
 
 
 
621f795
 
 
9b3729e
621f795
 
 
 
 
9b3729e
 
 
 
 
621f795
9b3729e
621f795
 
9b3729e
621f795
 
9b3729e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cabc901
9b3729e
 
 
 
 
 
 
621f795
9b3729e
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
                         )

combined_interface = gradio.Interface(
    [
        iface_1,
        iface_2
    ],
    title="Multiple Models Interface",
    description="This interface showcases multiple models"
)

combined_interface.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