Spaces:
Sleeping
Sleeping
created app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
+
|
5 |
+
# 1) load model once at startup
|
6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
7 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
8 |
+
"Nihirc/Prompt2MedImage",
|
9 |
+
torch_dtype=torch.float16 if device=="cuda" else torch.float32
|
10 |
+
).to(device)
|
11 |
+
|
12 |
+
def generate(prompt: str):
|
13 |
+
img = pipe(prompt).images[0]
|
14 |
+
return img
|
15 |
+
|
16 |
+
demo = gr.Interface(
|
17 |
+
fn=generate,
|
18 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter medical prompt…"),
|
19 |
+
outputs="image",
|
20 |
+
title="Prompt2MedImage",
|
21 |
+
description="Generate medical images from text prompts."
|
22 |
+
)
|
23 |
+
|
24 |
+
if __name__=="__main__":
|
25 |
+
demo.launch()
|