Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
from groq import Groq
|
3 |
+
client = Groq(
|
4 |
+
api_key="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",
|
5 |
+
)
|
6 |
+
def initialize_messages():
|
7 |
+
return [{"role": "system",
|
8 |
+
"content": """You are an experienced medical doctor with a strong background
|
9 |
+
in clinical diagnosis and patient care. Your role is to assist individuals by
|
10 |
+
offering accurate medical guidance, explaining health conditions in a clear and
|
11 |
+
empathetic manner, and providing advice in alignment with standard medical
|
12 |
+
practices and current healthcare guidelines in India."""}]
|
13 |
+
messages_prmt = initialize_messages()
|
14 |
+
print(messages_prmt)
|
15 |
+
def customLLMBot(user_input, history):
|
16 |
+
global messages_prmt
|
17 |
+
|
18 |
+
messages_prmt.append({"role": "user", "content": user_input})
|
19 |
+
|
20 |
+
response = client.chat.completions.create(
|
21 |
+
messages=messages_prmt,
|
22 |
+
model="llama3-8b-8192",
|
23 |
+
)
|
24 |
+
print(response)
|
25 |
+
LLM_reply = response.choices[0].message.content
|
26 |
+
messages_prmt.append({"role": "assistant", "content": LLM_reply})
|
27 |
+
|
28 |
+
return LLM_reply
|
29 |
+
iface = gradio.ChatInterface(customLLMBot,
|
30 |
+
chatbot=gradio.Chatbot(height=300),
|
31 |
+
textbox=gradio.Textbox(placeholder="Ask me a question related to medical field"),
|
32 |
+
title="MediAid",
|
33 |
+
description="Chat bot for medical assistance",
|
34 |
+
theme="soft",
|
35 |
+
examples=["hi","What is the process to get treatment in a government hospital", "What happens during a full body health check-up"],
|
36 |
+
submit_btn=True
|
37 |
+
)
|
38 |
+
iface.launch(share=True)
|