Update app.py
Browse files
app.py
CHANGED
|
@@ -157,7 +157,7 @@ Format the response clearly with headings for "Recommended Medicines", "Medicine
|
|
| 157 |
except Exception as e:
|
| 158 |
return f"Error: {str(e)}"
|
| 159 |
|
| 160 |
-
def send_medicine_to_recommender(api_key, medicine_names, csv_file
|
| 161 |
"""
|
| 162 |
Takes medicine names extracted from prescription and gets recommendations
|
| 163 |
"""
|
|
@@ -193,6 +193,14 @@ with gr.Blocks(title="Medicine Assistant") as app:
|
|
| 193 |
type="password"
|
| 194 |
)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
with gr.Tabs():
|
| 197 |
with gr.Tab("Prescription Medicine Extractor"):
|
| 198 |
gr.Markdown("## Prescription Medicine Extractor")
|
|
@@ -217,7 +225,7 @@ with gr.Blocks(title="Medicine Assistant") as app:
|
|
| 217 |
|
| 218 |
recommend_from_extract_btn.click(
|
| 219 |
fn=send_medicine_to_recommender,
|
| 220 |
-
inputs=[api_key_input, extracted_output,
|
| 221 |
outputs=recommendation_from_extract_output
|
| 222 |
)
|
| 223 |
|
|
@@ -226,7 +234,8 @@ with gr.Blocks(title="Medicine Assistant") as app:
|
|
| 226 |
1. Enter your Together API key
|
| 227 |
2. Upload a clear image of a prescription
|
| 228 |
3. Click 'Extract Medicines' to see the identified medicines
|
| 229 |
-
4. Optionally
|
|
|
|
| 230 |
|
| 231 |
### Note:
|
| 232 |
- Your API key is used only for the current session
|
|
@@ -243,13 +252,6 @@ with gr.Blocks(title="Medicine Assistant") as app:
|
|
| 243 |
label="Medicine Name",
|
| 244 |
placeholder="Enter a medicine name exactly as it appears in the dataset"
|
| 245 |
)
|
| 246 |
-
csv_file = gr.File(
|
| 247 |
-
label="Upload Medicine CSV (Optional)",
|
| 248 |
-
file_types=[".csv"],
|
| 249 |
-
type="file"
|
| 250 |
-
)
|
| 251 |
-
gr.Markdown("If no CSV is uploaded, the app will use the default 'medicine_dataset.csv' file.")
|
| 252 |
-
|
| 253 |
submit_btn = gr.Button("Get Recommendations", variant="primary")
|
| 254 |
|
| 255 |
with gr.Column():
|
|
@@ -257,7 +259,7 @@ with gr.Blocks(title="Medicine Assistant") as app:
|
|
| 257 |
|
| 258 |
submit_btn.click(
|
| 259 |
recommend_medicine,
|
| 260 |
-
inputs=[api_key_input, medicine_name,
|
| 261 |
outputs=recommendation_output
|
| 262 |
)
|
| 263 |
|
|
@@ -265,8 +267,7 @@ with gr.Blocks(title="Medicine Assistant") as app:
|
|
| 265 |
## How to use this tool:
|
| 266 |
1. Enter your Together API key (same key used across the application)
|
| 267 |
2. Enter a medicine name **exactly as it appears** in the CSV file
|
| 268 |
-
3.
|
| 269 |
-
4. Click "Get Recommendations" to see alternatives
|
| 270 |
|
| 271 |
### CSV Format Requirements:
|
| 272 |
The app expects a CSV with these columns:
|
|
|
|
| 157 |
except Exception as e:
|
| 158 |
return f"Error: {str(e)}"
|
| 159 |
|
| 160 |
+
def send_medicine_to_recommender(api_key, medicine_names, csv_file):
|
| 161 |
"""
|
| 162 |
Takes medicine names extracted from prescription and gets recommendations
|
| 163 |
"""
|
|
|
|
| 193 |
type="password"
|
| 194 |
)
|
| 195 |
|
| 196 |
+
# Create a file input for CSV that can be shared between tabs
|
| 197 |
+
csv_file_input = gr.File(
|
| 198 |
+
label="Upload Medicine CSV (Optional)",
|
| 199 |
+
file_types=[".csv"],
|
| 200 |
+
type="file"
|
| 201 |
+
)
|
| 202 |
+
gr.Markdown("If no CSV is uploaded, the app will use the default 'medicine_dataset.csv' file.")
|
| 203 |
+
|
| 204 |
with gr.Tabs():
|
| 205 |
with gr.Tab("Prescription Medicine Extractor"):
|
| 206 |
gr.Markdown("## Prescription Medicine Extractor")
|
|
|
|
| 225 |
|
| 226 |
recommend_from_extract_btn.click(
|
| 227 |
fn=send_medicine_to_recommender,
|
| 228 |
+
inputs=[api_key_input, extracted_output, csv_file_input], # Now correctly passing the csv_file_input
|
| 229 |
outputs=recommendation_from_extract_output
|
| 230 |
)
|
| 231 |
|
|
|
|
| 234 |
1. Enter your Together API key
|
| 235 |
2. Upload a clear image of a prescription
|
| 236 |
3. Click 'Extract Medicines' to see the identified medicines
|
| 237 |
+
4. Optionally upload a custom medicine dataset CSV
|
| 238 |
+
5. Click 'Get Recommendations for First Medicine' to find alternatives
|
| 239 |
|
| 240 |
### Note:
|
| 241 |
- Your API key is used only for the current session
|
|
|
|
| 252 |
label="Medicine Name",
|
| 253 |
placeholder="Enter a medicine name exactly as it appears in the dataset"
|
| 254 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
submit_btn = gr.Button("Get Recommendations", variant="primary")
|
| 256 |
|
| 257 |
with gr.Column():
|
|
|
|
| 259 |
|
| 260 |
submit_btn.click(
|
| 261 |
recommend_medicine,
|
| 262 |
+
inputs=[api_key_input, medicine_name, csv_file_input], # Using the shared csv_file_input
|
| 263 |
outputs=recommendation_output
|
| 264 |
)
|
| 265 |
|
|
|
|
| 267 |
## How to use this tool:
|
| 268 |
1. Enter your Together API key (same key used across the application)
|
| 269 |
2. Enter a medicine name **exactly as it appears** in the CSV file
|
| 270 |
+
3. Click "Get Recommendations" to see alternatives
|
|
|
|
| 271 |
|
| 272 |
### CSV Format Requirements:
|
| 273 |
The app expects a CSV with these columns:
|