Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,7 +78,8 @@ suggested_drugs = [
|
|
78 |
# Function to handle drug query
|
79 |
def query_drug(drug_name, chat_history):
|
80 |
if not drug_name.strip():
|
81 |
-
|
|
|
82 |
|
83 |
try:
|
84 |
result = qa_chain.invoke({"query": drug_name})
|
@@ -96,7 +97,13 @@ def query_drug(drug_name, chat_history):
|
|
96 |
else:
|
97 |
response = f"Error: An unexpected error occurred: {error_msg}"
|
98 |
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
# Gradio Interface
|
102 |
with gr.Blocks(title="DrugScan") as demo:
|
@@ -108,26 +115,28 @@ with gr.Blocks(title="DrugScan") as demo:
|
|
108 |
gr.Image(logo_url, width=150)
|
109 |
|
110 |
# Chat interface
|
111 |
-
chatbot = gr.Chatbot(label="Results")
|
112 |
drug_input = gr.Textbox(placeholder="Enter a drug name (e.g., 'Azirox')", label="Drug Name")
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
# Suggested drugs buttons
|
115 |
gr.Markdown("### Try These Drugs")
|
116 |
with gr.Row():
|
117 |
for drug in suggested_drugs:
|
118 |
-
gr.Button(drug)
|
119 |
-
|
120 |
-
|
|
|
121 |
outputs=chatbot
|
122 |
)
|
123 |
|
124 |
-
# Search button
|
125 |
-
drug_input.submit(
|
126 |
-
fn=query_drug,
|
127 |
-
inputs=[drug_input, chatbot],
|
128 |
-
outputs=chatbot
|
129 |
-
)
|
130 |
-
|
131 |
# Disclaimer
|
132 |
gr.Markdown("### Important Disclaimer")
|
133 |
gr.Markdown(
|
|
|
78 |
# Function to handle drug query
|
79 |
def query_drug(drug_name, chat_history):
|
80 |
if not drug_name.strip():
|
81 |
+
chat_history.append({"role": "assistant", "content": "Please enter a drug name."})
|
82 |
+
return chat_history
|
83 |
|
84 |
try:
|
85 |
result = qa_chain.invoke({"query": drug_name})
|
|
|
97 |
else:
|
98 |
response = f"Error: An unexpected error occurred: {error_msg}"
|
99 |
|
100 |
+
chat_history.append({"role": "user", "content": drug_name})
|
101 |
+
chat_history.append({"role": "assistant", "content": response})
|
102 |
+
return chat_history
|
103 |
+
|
104 |
+
# Function to handle suggested drug buttons
|
105 |
+
def query_suggested_drug(drug_name, chat_history):
|
106 |
+
return query_drug(drug_name, chat_history)
|
107 |
|
108 |
# Gradio Interface
|
109 |
with gr.Blocks(title="DrugScan") as demo:
|
|
|
115 |
gr.Image(logo_url, width=150)
|
116 |
|
117 |
# Chat interface
|
118 |
+
chatbot = gr.Chatbot(label="Results", type="messages")
|
119 |
drug_input = gr.Textbox(placeholder="Enter a drug name (e.g., 'Azirox')", label="Drug Name")
|
120 |
|
121 |
+
# Search button
|
122 |
+
search_btn = gr.Button("Search")
|
123 |
+
search_btn.click(
|
124 |
+
fn=query_drug,
|
125 |
+
inputs=[drug_input, chatbot],
|
126 |
+
outputs=chatbot
|
127 |
+
)
|
128 |
+
|
129 |
# Suggested drugs buttons
|
130 |
gr.Markdown("### Try These Drugs")
|
131 |
with gr.Row():
|
132 |
for drug in suggested_drugs:
|
133 |
+
btn = gr.Button(drug)
|
134 |
+
btn.click(
|
135 |
+
fn=query_suggested_drug,
|
136 |
+
inputs=[gr.State(value=drug), chatbot],
|
137 |
outputs=chatbot
|
138 |
)
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
# Disclaimer
|
141 |
gr.Markdown("### Important Disclaimer")
|
142 |
gr.Markdown(
|