Spaces:
Runtime error
Runtime error
neerajprad
commited on
Commit
·
5181338
1
Parent(s):
1009791
Colab update - remove share
Browse files- app.py +28 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
import torch
|
5 |
+
|
6 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
7 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
8 |
+
pipe = pipe.to(device)
|
9 |
+
|
10 |
+
|
11 |
+
def generate(celebrity, setting):
|
12 |
+
prompt = f"A poster of {celebrity} in {setting}, 35 mm, ultra detailed, cinematic light, photorealistic"
|
13 |
+
return pipe(prompt, num_inference_steps=50, num_images_per_prompt=1, guidance_scale=9).images[0]
|
14 |
+
|
15 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
16 |
+
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "crowdsourced-text2img")
|
17 |
+
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=generate,
|
20 |
+
title="Poster of celebrity X in setting Y",
|
21 |
+
inputs=[gr.Textbox(placeholder="Elon Musk"),
|
22 |
+
gr.Dropdown(["Mad Max", "Game of Thrones", "Pulp Fiction", "Moneyball", "The Sopranos", "Jurassic Park", "Cinderella", "The Lion King"], value="Mad Max")],
|
23 |
+
outputs=gr.Image(),
|
24 |
+
flagging_options=["great result", "satisfactory result", "needs improvement"],
|
25 |
+
flagging_callback=hf_writer
|
26 |
+
)
|
27 |
+
|
28 |
+
interface.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
diffusers
|
3 |
+
sklearn
|