Spaces:
Sleeping
Sleeping
updated app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
from diffusers import DiffusionPipeline
|
3 |
import torch
|
|
|
|
|
4 |
|
5 |
-
# Load model once at startup
|
6 |
pipe = DiffusionPipeline.from_pretrained("Nihirc/Prompt2MedImage")
|
7 |
if torch.cuda.is_available():
|
8 |
pipe = pipe.to("cuda")
|
9 |
|
10 |
def generate_image(prompt):
|
11 |
image = pipe(prompt).images[0]
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
iface = gr.Interface(
|
15 |
fn=generate_image,
|
16 |
inputs=gr.Textbox(label="Prompt"),
|
17 |
-
outputs=gr.
|
18 |
title="Medical Image Generator"
|
19 |
)
|
20 |
|
|
|
1 |
import gradio as gr
|
2 |
from diffusers import DiffusionPipeline
|
3 |
import torch
|
4 |
+
import base64
|
5 |
+
import io
|
6 |
|
|
|
7 |
pipe = DiffusionPipeline.from_pretrained("Nihirc/Prompt2MedImage")
|
8 |
if torch.cuda.is_available():
|
9 |
pipe = pipe.to("cuda")
|
10 |
|
11 |
def generate_image(prompt):
|
12 |
image = pipe(prompt).images[0]
|
13 |
+
|
14 |
+
# Convert to base64 for API compatibility
|
15 |
+
buffered = io.BytesIO()
|
16 |
+
image.save(buffered, format="PNG")
|
17 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
18 |
+
|
19 |
+
return img_str # Return base64 string directly
|
20 |
|
21 |
iface = gr.Interface(
|
22 |
fn=generate_image,
|
23 |
inputs=gr.Textbox(label="Prompt"),
|
24 |
+
outputs=gr.Textbox(label="Base64 Image"), # Changed from Image to Textbox
|
25 |
title="Medical Image Generator"
|
26 |
)
|
27 |
|