Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import numpy as np
|
|
7 |
import torchvision.transforms as transforms
|
8 |
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
|
9 |
from shiny.types import FileInfo
|
|
|
|
|
10 |
|
11 |
from transformers import SamModel
|
12 |
|
@@ -65,6 +67,12 @@ def server(input: Inputs, output: Outputs, session: Session):
|
|
65 |
combined.save(combined_file.name, "PNG", quality=100)
|
66 |
|
67 |
return original_file.name, combined_file.name
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
@render.image
|
70 |
def original_image():
|
@@ -80,6 +88,7 @@ def server(input: Inputs, output: Outputs, session: Session):
|
|
80 |
if result is None:
|
81 |
return None
|
82 |
_, img_path = result
|
83 |
-
|
|
|
84 |
|
85 |
app = App(app_ui, server)
|
|
|
7 |
import torchvision.transforms as transforms
|
8 |
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
|
9 |
from shiny.types import FileInfo
|
10 |
+
import base64
|
11 |
+
from io import BytesIO
|
12 |
|
13 |
from transformers import SamModel
|
14 |
|
|
|
67 |
combined.save(combined_file.name, "PNG", quality=100)
|
68 |
|
69 |
return original_file.name, combined_file.name
|
70 |
+
|
71 |
+
def image_to_base64(image):
|
72 |
+
buffered = BytesIO()
|
73 |
+
image.save(buffered, format="PNG")
|
74 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
75 |
+
return f"data:image/png;base64,{img_str}"
|
76 |
|
77 |
@render.image
|
78 |
def original_image():
|
|
|
88 |
if result is None:
|
89 |
return None
|
90 |
_, img_path = result
|
91 |
+
image = Image.open(img_path)
|
92 |
+
return {"src": image_to_base64(image), "width": "300px"}
|
93 |
|
94 |
app = App(app_ui, server)
|