File size: 1,672 Bytes
3194597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio
from groq import Groq
client = Groq(
    api_key="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",
)
def initialize_messages():
    return [{"role": "system",
             "content": """You are an experienced medical doctor with a strong background
             in clinical diagnosis and patient care. Your role is to assist individuals by
             offering accurate medical guidance, explaining health conditions in a clear and
              empathetic manner, and providing advice in alignment with standard medical
              practices and current healthcare guidelines in India."""}]
messages_prmt = initialize_messages()
print(messages_prmt)
def customLLMBot(user_input, history):
    global messages_prmt

    messages_prmt.append({"role": "user", "content": user_input})

    response = client.chat.completions.create(
        messages=messages_prmt,
        model="llama3-8b-8192",
    )
    print(response)
    LLM_reply = response.choices[0].message.content
    messages_prmt.append({"role": "assistant", "content": LLM_reply})

    return LLM_reply
iface = gradio.ChatInterface(customLLMBot,
                     chatbot=gradio.Chatbot(height=300),
                     textbox=gradio.Textbox(placeholder="Ask me a question related to medical field"),
                     title="MediAid",
                     description="Chat bot for medical assistance",
                     theme="soft",
                     examples=["hi","What is the process to get treatment in a government hospital", "What happens during a full body health check-up"],
                     submit_btn=True
                     )
iface.launch(share=True)