File size: 3,947 Bytes
498aec5
 
 
2f5f716
498aec5
 
9af06c0
498aec5
 
 
 
 
a07d9df
b29011e
498aec5
 
 
 
 
 
 
 
 
 
 
88ac13c
498aec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca39493
6ba02ef
6d80f21
8e981b2
ca39493
 
498aec5
 
 
 
 
 
 
 
88ac13c
498aec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
from gradio_client import Client
import time

hf_key = os.environ['HF_API_KEY']
client_url = os.environ['BK_URL']

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
]
msg_count = 0
 
client = Client(client_url, hf_token=hf_key)
def get_llm_rsp(text):
  rsp = client.predict(
		text,	# str  in 'Input your question:' Textbox component
		api_name="/get_llm_resp"
  )
  return rsp

def add_text(history, text):
    global messages  #message[list] is defined globally
    history = history + [(text,'')]
    messages = messages + [{"role":'user', 'content': text}]
    return history, text

def generate_response(history, text):
        global messages, msg_count

        #arsp = bizbot([chatbot, text], api_name="bizbot-api")
        response_msg = get_llm_rsp(text)

        msg_count = msg_count + 1
        messages = messages + [{"role":'assistant', 'content': response_msg}]
        
        for char in response_msg:

            history[-1][1] += char
            time.sleep(0.03)
            yield history


def calc_cost():
  global msg_count
  return msg_count


with gr.Blocks() as demo:
    
    gr.Markdown(value="## MedBot")
    gr.Markdown(value="Welcome to MedBot – Your Personal Health Assistant. I am here to provide information on various diseases and medical conditions. Please keep in mind that while I can offer valuable insights, my responses are not a substitute for professional medical advice, diagnosis, or treatment.")
    gr.Markdown(value="Bot helps with medical information on several common medical disorders, conditions, tests, and treatments, including high-profile diseases such as \
    Alzheimer’s disease, cancer, and heart attack. It uses language that laypersons can understand.")
    #gr.Markdown(value="It supports multiple Indian languages like English, Marathi (मराठी), Hindi (हिन्दी), Bengali (বাংলা), Telugu (తెలుగు),Tamil (தமிழ்), Urdu (اردو), Gujarati (ગુજરાતી), Kannada (ಕನ್ನಡ), Punjabi (ਪੰਜਾਬੀ),Malayalam (മലയാളം), Odia (ଓଡ଼ିଆ),Assamese (অসমীয়া). You will get the response in the language you ask the question.")
    gr.Markdown(value="**For accurate and personalized guidance, always consult with a qualified healthcare professional. If you have a specific question about a particular disease or health concern, feel free to ask, and I'll do my best to assist you with reliable and informative responses.\
    Your health is important, and I'm here to support you on your journey to better understanding various medical conditions. Let's explore together, keeping your well-being in mind at all times.**")
    chatbot = gr.Chatbot(value=[], label="MedBot")

    txt = gr.Textbox(
                label="Input your question:",
                placeholder="Enter text and press enter",
            )    #.style(container=False)
    gr.Examples(
        label="Question examples",
        examples=[["Why do we get fever?"], 
         ["What is cancer?"],
         ["What is treatment for cancer?"],
                 ],
        inputs=[txt],)
    btn = gr.Button("Submit")


    count_msg_view = gr.Textbox(label='Number of questions answered in current conversation:',value=0)
    #btn2 = gr.Button("Clear and Start New Conversation ")

    txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
            generate_response, inputs =[chatbot, txt],outputs = chatbot,).then(
            calc_cost, outputs=count_msg_view)
    btn.click(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
            generate_response, inputs =[chatbot, txt],outputs = chatbot,).then(
            calc_cost, outputs=count_msg_view)

    #Button click action to clear conversation
    #btn2.click(clear_conv,inputs=chatbot, outputs=[chatbot, count_msg_view])

demo.queue()
demo.launch(debug=True)