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