File size: 4,167 Bytes
033f9f2
355da42
 
 
 
 
 
 
 
 
 
 
 
 
 
41af6a9
355da42
 
 
 
 
 
 
 
90a4d87
41af6a9
 
 
 
 
 
355da42
41af6a9
355da42
 
 
 
 
0cb0826
 
 
 
 
 
 
 
 
355da42
90a4d87
355da42
5d31b2a
 
355da42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a4d87
355da42
 
 
 
 
 
 
 
0cb0826
 
 
 
 
 
 
c291536
0cb0826
355da42
 
5d31b2a
72c9ffc
355da42
 
 
c35ea6c
355da42
 
90a4d87
 
5d31b2a
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#C408
import peft
import bitsandbytes
import datasets
import accelerate
import loralib
import transformers
import sacremoses
import sentencepiece
import gradio as gr

import os

import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM,AutoTokenizer, LlamaForCausalLM

import joblib
from deployML import predd

import time

#load the chatbot


model = LlamaForCausalLM.from_pretrained(
    "medalpaca/medalpaca-7b",
    return_dict=True,
    load_in_8bit=True,
    device_map="auto",
)

tokenizer = AutoTokenizer.from_pretrained("medalpaca/medalpaca-7b")


#load the first interface

def fn(*args):
    global symptoms
    all_symptoms = [symptom for symptom_list in args for symptom in symptom_list]
    if len(all_symptoms) > 17:
        raise gr.Error("Please select a maximum of 17 symptoms.")
    elif len(all_symptoms) < 3:
        raise gr.Error("Please select at least 3 symptoms.")
        symptoms = all_symptoms  # Update global symptoms list
    loaded_rf = joblib.load("model_joblib")
    return predd(loaded_rf,symptoms)



symptoms = []



demo = gr.Interface(
    fn, [
        gr.CheckboxGroup(['itching', 'skin rash', 'nodal skin eruptions', 'dischromic patches'], label='Skin Issues'),
        gr.CheckboxGroup(['continuous sneezing', 'shivering', 'chills', 'cough', 'breathlessness', 'phlegm', 'blood in sputum', 'throat irritation', 'runny nose', 'congestion', 'loss of smell', 'sinus pressure'], label='Respiratory Problems'),
        gr.CheckboxGroup(['stomach pain', 'acidity', 'ulcers on tongue', 'vomiting', 'nausea', 'loss of appetite', 'abdominal pain', 'burning micturition', 'spotting urination', 'passage of gases', 'internal itching', 'indigestion', 'muscle wasting', 'patches in throat', 'constipation'], label='Digestive Complaints'),
        gr.CheckboxGroup(['high fever', 'fatigue', 'weight loss', 'restlessness', 'lethargy', 'mild fever'], label='Fever and Fatigue'),
        gr.CheckboxGroup(['blurred and distorted vision', 'red spots over body', 'pain behind the eyes', 'redness of eyes'], label='Vision and Eye Problems'),
        gr.CheckboxGroup(['chest pain', 'fast heart rate', 'swelling of stomach'], label='Cardiovascular Issues'),
        gr.CheckboxGroup(['muscle pain', 'joint pain', 'pain in anal region', 'painful walking', 'movement stiffness'], label='Joint and Muscle Pain'),
        gr.CheckboxGroup(['headache', 'dizziness', 'loss of balance', 'lack of concentration', 'stiff neck', 'depression', 'irritability', 'visual disturbances', 'back pain', 'weakness in limbs', 'neck pain', 'weakness of one body side', 'altered sensorium'], label='Neurological Symptoms'),
        gr.CheckboxGroup(['dark urine', 'sweating', 'mucoid sputum', 'toxic look (typhos)', 'bladder discomfort', 'foul smell of urine', 'continuous feel of urine'], label='Urinary Issues'),
        gr.CheckboxGroup(['skin peeling', 'silver like dusting', 'small dents in nails', 'inflammatory nails', 'blister', 'red sore around nose', 'yellow crust ooze'], label='Skin Abnormalities'),
        gr.CheckboxGroup(['family history', 'headache', 'mood swings', 'anxiety', 'slurred speech', 'palpitations', 'drying and tingling lips'], label='Psychological Symptoms'),
        gr.CheckboxGroup(['knee pain', 'hip joint pain', 'swelling joints'], label='Joint and Bone Issues'),
        gr.CheckboxGroup(['spinning movements', 'unsteadiness'], label='Neurological Movements')
    ],
    outputs="textbox",allow_flagging="never"
)






def predict(message, history):
    prompt = f"""
    Answer the following question:
    {message}/n
    Answer:
    """
    batch = tokenizer(prompt, return_tensors='pt')
    with torch.cuda.amp.autocast():
        output_tokens = model.generate(**batch, max_new_tokens=200)
    return tokenizer.decode(output_tokens[0], skip_special_tokens=True).replace(prompt,"")


loaded_rf = joblib.load("model_joblib")
Fmessage="hello, I'm here to help you!"



chatbot=gr.ChatInterface(predict, chatbot=gr.Chatbot(value=[(None, Fmessage)],),clear_btn=None, retry_btn=None, undo_btn=None)


gr.TabbedInterface(
    [demo, chatbot], ["symptoms checker", "chatbot"]
).queue().launch()