Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -46,8 +46,10 @@ retriever = vectorstore.as_retriever()
|
|
46 |
|
47 |
from langchain_core.prompts import PromptTemplate
|
48 |
|
49 |
-
template = ("""You are a pharmacist and medical expert.
|
50 |
Use the provided context to answer the question.
|
|
|
|
|
51 |
If you don't know the answer, say so. Explain your answer in detail.
|
52 |
Do not discuss the context in your response; just provide the answer directly.
|
53 |
|
@@ -82,63 +84,82 @@ def rag_memory_stream(text):
|
|
82 |
# Title and description for the app
|
83 |
title = "AI Medical Assistant for Drug Information and Side Effects"
|
84 |
description = """
|
|
|
85 |
This AI-powered chatbot is designed to provide reliable information about drugs, their side effects, and related medical conditions.
|
86 |
-
It utilizes the Groq API and LangChain to deliver real-time, accurate responses.
|
87 |
|
88 |
Ask questions like:
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
96 |
"""
|
97 |
|
98 |
# Customizing Gradio interface for a better look
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
demo = gr.Interface(
|
100 |
fn=rag_memory_stream,
|
101 |
inputs=gr.Textbox(
|
102 |
-
lines=
|
103 |
placeholder="Type your medical question here...",
|
104 |
label="Your Medical Question"
|
105 |
),
|
106 |
outputs=gr.Textbox(
|
107 |
-
lines=
|
108 |
label="AI Response"
|
109 |
),
|
110 |
title=title,
|
111 |
description=description,
|
112 |
-
|
113 |
-
allow_flagging="never"
|
|
|
114 |
)
|
115 |
|
116 |
-
# # Launching the app
|
117 |
-
# demo.launch(share=True)
|
118 |
-
|
119 |
-
# import gradio as gr
|
120 |
-
|
121 |
-
# def rag_memory_stream(text):
|
122 |
-
# partial_text = ""
|
123 |
-
# for new_text in rag_chain.stream(text):
|
124 |
-
# partial_text += new_text
|
125 |
-
# yield partial_text
|
126 |
-
|
127 |
-
# examples = ['I feel dizzy', 'what is the possible sickness for fatigue']
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
# title = "Real-time AI App with Groq API and LangChain to Answer medical questions"
|
133 |
-
# demo = gr.Interface(
|
134 |
-
# title=title,
|
135 |
-
# fn=rag_memory_stream,
|
136 |
-
# inputs="text",
|
137 |
-
# outputs="text",
|
138 |
-
# examples=examples,
|
139 |
-
# allow_flagging="never",
|
140 |
-
# )
|
141 |
-
|
142 |
-
|
143 |
if __name__ == "__main__":
|
144 |
demo.launch()
|
|
|
46 |
|
47 |
from langchain_core.prompts import PromptTemplate
|
48 |
|
49 |
+
template = ("""You are a pharmacist and medical expert.
|
50 |
Use the provided context to answer the question.
|
51 |
+
If the question is related to medical condition, drug name
|
52 |
+
and side effects that are not in the context, look online and answer them.
|
53 |
If you don't know the answer, say so. Explain your answer in detail.
|
54 |
Do not discuss the context in your response; just provide the answer directly.
|
55 |
|
|
|
84 |
# Title and description for the app
|
85 |
title = "AI Medical Assistant for Drug Information and Side Effects"
|
86 |
description = """
|
87 |
+
<div class="description">
|
88 |
This AI-powered chatbot is designed to provide reliable information about drugs, their side effects, and related medical conditions.
|
89 |
+
It utilizes the Groq API and LangChain to deliver real-time, accurate responses.
|
90 |
|
91 |
Ask questions like:
|
92 |
+
<ul>
|
93 |
+
<li>What are the side effects of taking aspirin daily?</li>
|
94 |
+
<li>What is the recommended treatment for a common cold?</li>
|
95 |
+
<li>What is the disease for constant fatigue and muscle weakness?</li>
|
96 |
+
<li>What are the symptoms of diabetes?</li>
|
97 |
+
<li>How can hypertension be managed?</li>
|
98 |
+
</ul>
|
99 |
+
|
100 |
+
<strong>Disclaimer:</strong> This chatbot is for informational purposes only and is not a substitute for professional medical advice.
|
101 |
+
</div>
|
102 |
"""
|
103 |
|
104 |
# Customizing Gradio interface for a better look
|
105 |
+
|
106 |
+
# HTML for custom styling
|
107 |
+
custom_css = """
|
108 |
+
body {
|
109 |
+
background-color: #f9f9f9;
|
110 |
+
font-family: Arial, sans-serif;
|
111 |
+
margin: 0;
|
112 |
+
padding: 0;
|
113 |
+
}
|
114 |
+
|
115 |
+
#interface-container {
|
116 |
+
max-width: 800px;
|
117 |
+
margin: 50px auto;
|
118 |
+
padding: 20px;
|
119 |
+
background: linear-gradient(145deg, #ffffff, #f0f0f0);
|
120 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
121 |
+
border-radius: 10px;
|
122 |
+
border: 1px solid #e0e0e0;
|
123 |
+
}
|
124 |
+
|
125 |
+
h1 {
|
126 |
+
text-align: center;
|
127 |
+
color: #333;
|
128 |
+
}
|
129 |
+
|
130 |
+
.description {
|
131 |
+
text-align: justify;
|
132 |
+
color: #555;
|
133 |
+
font-size: 1rem;
|
134 |
+
margin-bottom: 20px;
|
135 |
+
}
|
136 |
+
|
137 |
+
footer {
|
138 |
+
text-align: center;
|
139 |
+
color: #777;
|
140 |
+
margin-top: 30px;
|
141 |
+
font-size: 0.9rem;
|
142 |
+
}
|
143 |
+
"""
|
144 |
+
|
145 |
+
# Customizing Gradio interface with additional CSS and content
|
146 |
demo = gr.Interface(
|
147 |
fn=rag_memory_stream,
|
148 |
inputs=gr.Textbox(
|
149 |
+
lines=5,
|
150 |
placeholder="Type your medical question here...",
|
151 |
label="Your Medical Question"
|
152 |
),
|
153 |
outputs=gr.Textbox(
|
154 |
+
lines=15, # Reduced line count for better layout
|
155 |
label="AI Response"
|
156 |
),
|
157 |
title=title,
|
158 |
description=description,
|
159 |
+
css=custom_css,
|
160 |
+
allow_flagging="never",
|
161 |
+
live=True
|
162 |
)
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
if __name__ == "__main__":
|
165 |
demo.launch()
|