Update app.py
Browse files
app.py
CHANGED
|
@@ -35,11 +35,9 @@ def make_gradcam_heatmap(img_array, model):
|
|
| 35 |
|
| 36 |
def predict_from_base64(base64_string):
|
| 37 |
try:
|
| 38 |
-
# Remove data URL prefix if present
|
| 39 |
if ',' in base64_string:
|
| 40 |
base64_string = base64_string.split(',')[1]
|
| 41 |
|
| 42 |
-
# Decode base64 to image
|
| 43 |
image_bytes = base64.b64decode(base64_string)
|
| 44 |
img = Image.open(io.BytesIO(image_bytes)).convert('RGB')
|
| 45 |
|
|
@@ -102,7 +100,6 @@ def predict_from_image(input_image):
|
|
| 102 |
|
| 103 |
return output_image, result_text
|
| 104 |
|
| 105 |
-
# Two interfaces: one for browser (image upload), one for API (base64)
|
| 106 |
image_interface = gr.Interface(
|
| 107 |
fn=predict_from_image,
|
| 108 |
inputs=gr.Image(label="Upload Histopathology Image"),
|
|
@@ -129,21 +126,4 @@ demo = gr.TabbedInterface(
|
|
| 129 |
["Upload Image", "API (Base64)"]
|
| 130 |
)
|
| 131 |
|
| 132 |
-
demo.launch()
|
| 133 |
-
```
|
| 134 |
-
|
| 135 |
-
---
|
| 136 |
-
|
| 137 |
-
## What Changed:
|
| 138 |
-
|
| 139 |
-
1. **Two interfaces** — one for browser upload, one for API with base64
|
| 140 |
-
2. **New API endpoint** — `/predict_base64` accepts base64 text
|
| 141 |
-
3. **Browser still works** — Users can still upload images normally
|
| 142 |
-
|
| 143 |
-
---
|
| 144 |
-
|
| 145 |
-
## After Update, Change n8n HTTP Request1:
|
| 146 |
-
|
| 147 |
-
**URL:**
|
| 148 |
-
```
|
| 149 |
-
https://hixoop-model-v1.hf.space/gradio_api/call/predict_base64
|
|
|
|
| 35 |
|
| 36 |
def predict_from_base64(base64_string):
|
| 37 |
try:
|
|
|
|
| 38 |
if ',' in base64_string:
|
| 39 |
base64_string = base64_string.split(',')[1]
|
| 40 |
|
|
|
|
| 41 |
image_bytes = base64.b64decode(base64_string)
|
| 42 |
img = Image.open(io.BytesIO(image_bytes)).convert('RGB')
|
| 43 |
|
|
|
|
| 100 |
|
| 101 |
return output_image, result_text
|
| 102 |
|
|
|
|
| 103 |
image_interface = gr.Interface(
|
| 104 |
fn=predict_from_image,
|
| 105 |
inputs=gr.Image(label="Upload Histopathology Image"),
|
|
|
|
| 126 |
["Upload Image", "API (Base64)"]
|
| 127 |
)
|
| 128 |
|
| 129 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|