Spaces:
Runtime error
Runtime error
Commit
·
092a751
1
Parent(s):
5be5d4b
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline, Wav2Vec2Processor, AutoModelForCTC
|
2 |
+
import torch
|
3 |
+
from torch import autocast
|
4 |
+
from diffusers import StableDiffusionPipeline
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
8 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token='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', revision="fp16", torch_dtype=torch.float16)
|
9 |
+
device = 'cuda'
|
10 |
+
#has_cuda = torch.cuda.is_available()
|
11 |
+
#device = torch.device('cpu' if not has_cuda else 'cuda')
|
12 |
+
pipe = pipe.to(device)
|
13 |
+
|
14 |
+
def convert(prompt):
|
15 |
+
with autocast("cuda"):
|
16 |
+
image = pipe(prompt)["sample"][0]
|
17 |
+
return image
|
18 |
+
|
19 |
+
gr.Interface(convert,
|
20 |
+
inputs = [gr.inputs.Textbox(label="Enter text")],
|
21 |
+
outputs = [gr.outputs.Image(label="Generated Image")],
|
22 |
+
title="Text to Image Generation").launch()
|