Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,7 +47,9 @@ def extract_medicines(image_files):
|
|
47 |
if not image_files:
|
48 |
return "Please upload a prescription image."
|
49 |
|
50 |
-
|
|
|
|
|
51 |
|
52 |
# Specific prompt to extract only medicine names
|
53 |
text = "Extract ONLY the names of medications/medicines from this prescription image. Format the output as a numbered list of medicine names only, without dosages or instructions."
|
@@ -106,22 +108,15 @@ with gr.Blocks() as demo:
|
|
106 |
outputs=output
|
107 |
)
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
["examples/prescription1.jpg"],
|
112 |
-
["examples/prescription2.jpg"],
|
113 |
-
],
|
114 |
-
inputs=image_input,
|
115 |
-
outputs=output,
|
116 |
-
fn=extract_medicines,
|
117 |
-
cache_examples=True,
|
118 |
-
)
|
119 |
|
120 |
gr.Markdown("""
|
121 |
### Notes:
|
122 |
- This app is optimized to run on CPU
|
123 |
- Upload clear images of prescriptions for best results
|
124 |
- Only medicine names will be extracted
|
|
|
125 |
""")
|
126 |
|
127 |
demo.queue()
|
|
|
47 |
if not image_files:
|
48 |
return "Please upload a prescription image."
|
49 |
|
50 |
+
# Handle file inputs correctly
|
51 |
+
image_paths = [file.name for file in image_files] if isinstance(image_files, list) else [image_files.name]
|
52 |
+
images = [load_image(path) for path in image_paths]
|
53 |
|
54 |
# Specific prompt to extract only medicine names
|
55 |
text = "Extract ONLY the names of medications/medicines from this prescription image. Format the output as a numbered list of medicine names only, without dosages or instructions."
|
|
|
108 |
outputs=output
|
109 |
)
|
110 |
|
111 |
+
# Note: For examples to work with current Gradio versions, you need a different approach
|
112 |
+
# than what I previously provided. Remove examples for now to fix the immediate error.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
gr.Markdown("""
|
115 |
### Notes:
|
116 |
- This app is optimized to run on CPU
|
117 |
- Upload clear images of prescriptions for best results
|
118 |
- Only medicine names will be extracted
|
119 |
+
- Processing might take a minute or two on CPU
|
120 |
""")
|
121 |
|
122 |
demo.queue()
|