Spaces:
Running
Running
Tafazzul-Nadeeem
commited on
Commit
·
2b2e182
1
Parent(s):
32553dc
Chatbot ready
Browse files- app.py +13 -2
- faiss_index_store/index.faiss +0 -0
- faiss_index_store/index.pkl +0 -0
- prompts.py +10 -7
- ratelist_offers.docx +0 -0
- ratelist_offers.pdf +0 -0
app.py
CHANGED
|
@@ -83,6 +83,7 @@ with gr.Blocks() as demo:
|
|
| 83 |
has_image_url = any("image_url" in item for item in messages[0]["content"])
|
| 84 |
if has_image_url:
|
| 85 |
prescription_text = agent4_get_prescription_text(messages)
|
|
|
|
| 86 |
history.append({"role": "system", "content": prescription_text})
|
| 87 |
|
| 88 |
if message["text"] is not None:
|
|
@@ -118,19 +119,20 @@ with gr.Blocks() as demo:
|
|
| 118 |
clean_messages.append(clean_msg)
|
| 119 |
########################### AGENTIC WORKFLOW ##########################
|
| 120 |
# Call Agent1- the RAG Decision Agent
|
|
|
|
| 121 |
if clean_messages[-1]["role"] == "system" and "No prescription found" in clean_messages[-1]["content"]:
|
| 122 |
# If the last message is a system message with "No prescription found", skip RAG decision
|
| 123 |
rag_decision = False
|
| 124 |
elif clean_messages[-2]["role"] == "system" and "No prescription found" in clean_messages[-2]["content"]:
|
| 125 |
rag_decision = False
|
| 126 |
else:
|
| 127 |
-
rag_query = ""
|
| 128 |
# Get the last 10 messages in the format "role: <message>"
|
| 129 |
last_10 = clean_messages[-10:] if len(clean_messages) > 10 else clean_messages
|
| 130 |
rag_query = "\n".join(
|
| 131 |
f"{msg['role']}: {msg['content'][0]['text'] if isinstance(msg['content'], list) and msg['content'] and 'text' in msg['content'][0] else ''}"
|
| 132 |
for msg in last_10
|
| 133 |
)
|
|
|
|
| 134 |
rag_decision = agent1_rag_decision(rag_query)
|
| 135 |
|
| 136 |
if rag_decision == True:
|
|
@@ -163,7 +165,16 @@ with gr.Blocks() as demo:
|
|
| 163 |
|
| 164 |
|
| 165 |
##########################################################################
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
chat_input = gr.MultimodalTextbox(
|
| 168 |
interactive=True,
|
| 169 |
file_count="multiple",
|
|
|
|
| 83 |
has_image_url = any("image_url" in item for item in messages[0]["content"])
|
| 84 |
if has_image_url:
|
| 85 |
prescription_text = agent4_get_prescription_text(messages)
|
| 86 |
+
print(f"Prescription Text: {prescription_text}")
|
| 87 |
history.append({"role": "system", "content": prescription_text})
|
| 88 |
|
| 89 |
if message["text"] is not None:
|
|
|
|
| 119 |
clean_messages.append(clean_msg)
|
| 120 |
########################### AGENTIC WORKFLOW ##########################
|
| 121 |
# Call Agent1- the RAG Decision Agent
|
| 122 |
+
rag_query = ""
|
| 123 |
if clean_messages[-1]["role"] == "system" and "No prescription found" in clean_messages[-1]["content"]:
|
| 124 |
# If the last message is a system message with "No prescription found", skip RAG decision
|
| 125 |
rag_decision = False
|
| 126 |
elif clean_messages[-2]["role"] == "system" and "No prescription found" in clean_messages[-2]["content"]:
|
| 127 |
rag_decision = False
|
| 128 |
else:
|
|
|
|
| 129 |
# Get the last 10 messages in the format "role: <message>"
|
| 130 |
last_10 = clean_messages[-10:] if len(clean_messages) > 10 else clean_messages
|
| 131 |
rag_query = "\n".join(
|
| 132 |
f"{msg['role']}: {msg['content'][0]['text'] if isinstance(msg['content'], list) and msg['content'] and 'text' in msg['content'][0] else ''}"
|
| 133 |
for msg in last_10
|
| 134 |
)
|
| 135 |
+
|
| 136 |
rag_decision = agent1_rag_decision(rag_query)
|
| 137 |
|
| 138 |
if rag_decision == True:
|
|
|
|
| 165 |
|
| 166 |
|
| 167 |
##########################################################################
|
| 168 |
+
gr.Markdown(
|
| 169 |
+
"""
|
| 170 |
+
<h1 style='text-align: center; font-size: 2em; color: #2c3e50; margin-bottom: 0.2em;'>
|
| 171 |
+
MedScan Diagnostic Services Chatbot (Agentic AI framework powered by OpenAI)
|
| 172 |
+
</h1>
|
| 173 |
+
"""
|
| 174 |
+
)
|
| 175 |
+
chatbot = gr.Chatbot(type="messages",
|
| 176 |
+
render_markdown=True,
|
| 177 |
+
height=600)
|
| 178 |
chat_input = gr.MultimodalTextbox(
|
| 179 |
interactive=True,
|
| 180 |
file_count="multiple",
|
faiss_index_store/index.faiss
CHANGED
|
Binary files a/faiss_index_store/index.faiss and b/faiss_index_store/index.faiss differ
|
|
|
faiss_index_store/index.pkl
CHANGED
|
Binary files a/faiss_index_store/index.pkl and b/faiss_index_store/index.pkl differ
|
|
|
prompts.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
bot_welcome_message = """Hello! I'm **
|
| 2 |
I am programmed to assist you with information about our diagnostic services and
|
| 3 |
current running offers and discounts.
|
| 4 |
You can ask questions or share part of your prescription (without names or any
|
|
@@ -17,14 +17,14 @@ You can also answer questions based on the information provided by the user but
|
|
| 17 |
only regarding the diagnostic services business.
|
| 18 |
If the user has uploaded an image and an agent has replied in the message that
|
| 19 |
No prescription found, then just reply "The image does not seem like a prescription, please
|
| 20 |
-
upload good quality staright images of prescription without any private information
|
| 21 |
-
and nothing else.
|
| 22 |
Do not provide any medical advice or diagnosis.
|
| 23 |
|
| 24 |
Safeguards:
|
| 25 |
1. If the user uploads a prescription image, and the agent which reads the
|
| 26 |
prescription has replied with some tests, then after your reply, always ask if
|
| 27 |
-
you had missed any test.
|
| 28 |
2. Do not provide any information other than the information available in the
|
| 29 |
knowledge base, even if the user asks for it.
|
| 30 |
2. If you are giving information about the cost of a test or any offers, always
|
|
@@ -43,10 +43,13 @@ Provide the response in markdown format.
|
|
| 43 |
prescription_text_user = f"""You are an agent of a Diagnostics Lab agentic AI
|
| 44 |
Chatbot system using RAG on a knowledge base. Your job is to extract the
|
| 45 |
lab tests advised by the doctor in the prescription image uploaded by the user.
|
| 46 |
-
Check if the image contains a medical prescription, if not, just reply
|
| 47 |
-
"No prescription found". DO NOT provide any other information about the image
|
| 48 |
-
if the image is not a prescription.
|
| 49 |
If the image is a prescription, extract the tests advised by the doctor and
|
| 50 |
using your knowledge about those tests, enumerate those in the reply.
|
| 51 |
Do not reply anything else other than the tests advised by the doctor.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
"""
|
|
|
|
| 1 |
+
bot_welcome_message = """Hello! I'm **Ashish**, your **AI assistant**.
|
| 2 |
I am programmed to assist you with information about our diagnostic services and
|
| 3 |
current running offers and discounts.
|
| 4 |
You can ask questions or share part of your prescription (without names or any
|
|
|
|
| 17 |
only regarding the diagnostic services business.
|
| 18 |
If the user has uploaded an image and an agent has replied in the message that
|
| 19 |
No prescription found, then just reply "The image does not seem like a prescription, please
|
| 20 |
+
upload good quality staright images of prescription without any private information,
|
| 21 |
+
like name, age, etc." and nothing else.
|
| 22 |
Do not provide any medical advice or diagnosis.
|
| 23 |
|
| 24 |
Safeguards:
|
| 25 |
1. If the user uploads a prescription image, and the agent which reads the
|
| 26 |
prescription has replied with some tests, then after your reply, always ask if
|
| 27 |
+
you had missed any test. If the adds any test, then add it in your previous reply.
|
| 28 |
2. Do not provide any information other than the information available in the
|
| 29 |
knowledge base, even if the user asks for it.
|
| 30 |
2. If you are giving information about the cost of a test or any offers, always
|
|
|
|
| 43 |
prescription_text_user = f"""You are an agent of a Diagnostics Lab agentic AI
|
| 44 |
Chatbot system using RAG on a knowledge base. Your job is to extract the
|
| 45 |
lab tests advised by the doctor in the prescription image uploaded by the user.
|
|
|
|
|
|
|
|
|
|
| 46 |
If the image is a prescription, extract the tests advised by the doctor and
|
| 47 |
using your knowledge about those tests, enumerate those in the reply.
|
| 48 |
Do not reply anything else other than the tests advised by the doctor.
|
| 49 |
+
|
| 50 |
+
Safeguards:
|
| 51 |
+
1. If the image is not a prescription, just reply "No prescription found"
|
| 52 |
+
2. Donot extract anything if the image is not a prescription, just reply
|
| 53 |
+
"No prescription found".
|
| 54 |
+
3. Do not answer the user query, the user query is just for context.
|
| 55 |
"""
|
ratelist_offers.docx
CHANGED
|
Binary files a/ratelist_offers.docx and b/ratelist_offers.docx differ
|
|
|
ratelist_offers.pdf
CHANGED
|
Binary files a/ratelist_offers.pdf and b/ratelist_offers.pdf differ
|
|
|