Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from hf_diffusion_service import HFDiffusionService
|
| 3 |
|
| 4 |
-
|
| 5 |
-
try:
|
| 6 |
-
service = HFDiffusionService()
|
| 7 |
-
except Exception as e:
|
| 8 |
-
print(f"Failed to initialize HFDiffusionService: {e}")
|
| 9 |
-
service = None
|
| 10 |
|
| 11 |
-
# Define Gradio function
|
| 12 |
def generate_ct(mask_image):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
result = service.generate_image(mask_image)
|
| 16 |
-
if result is None:
|
| 17 |
-
return "Error generating image."
|
| 18 |
-
return result
|
| 19 |
|
| 20 |
-
#
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=generate_ct,
|
| 23 |
inputs=gr.Image(type="pil", label="Segmentation Mask"),
|
| 24 |
outputs=gr.Image(type="pil", label="Generated CT Scan"),
|
| 25 |
title="Conditional Diffusion Medical Image Generator",
|
| 26 |
-
description="Upload or draw a
|
| 27 |
)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from hf_diffusion_service import HFDiffusionService
|
| 3 |
|
| 4 |
+
service = HFDiffusionService()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 6 |
def generate_ct(mask_image):
|
| 7 |
+
# Return the PIL image directly
|
| 8 |
+
return service.generate_image(mask_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# ✅ Single-interface Gradio app
|
| 11 |
demo = gr.Interface(
|
| 12 |
fn=generate_ct,
|
| 13 |
inputs=gr.Image(type="pil", label="Segmentation Mask"),
|
| 14 |
outputs=gr.Image(type="pil", label="Generated CT Scan"),
|
| 15 |
title="Conditional Diffusion Medical Image Generator",
|
| 16 |
+
description="Upload or draw a mask to generate a synthetic CT scan"
|
| 17 |
)
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|