Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,32 +2,40 @@ import gradio as gr
|
|
| 2 |
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
-
subprocess.check_call(["pip", "install", "
|
| 6 |
subprocess.check_call(["pip", "install", "torch"])
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return res
|
| 18 |
-
|
| 19 |
-
description = """
|
| 20 |
-
<p>
|
| 21 |
-
<center>
|
| 22 |
-
Multi-domain Summarisation Between English and Hindi
|
| 23 |
-
</center>
|
| 24 |
-
</p>
|
| 25 |
-
"""
|
| 26 |
|
|
|
|
| 27 |
iface = gr.Interface(
|
| 28 |
-
fn=
|
| 29 |
-
inputs="
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
iface.launch()
|
|
|
|
| 2 |
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
+
subprocess.check_call(["pip", "install", "safetensors"])
|
| 6 |
subprocess.check_call(["pip", "install", "torch"])
|
| 7 |
+
subprocess.check_call(["pip", "install", "diffusers"])
|
| 8 |
|
| 9 |
+
import torch
|
| 10 |
+
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
|
| 11 |
+
from huggingface_hub import hf_hub_download
|
| 12 |
+
from safetensors.torch import load_file
|
| 13 |
|
| 14 |
+
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 15 |
+
repo = "ByteDance/SDXL-Lightning"
|
| 16 |
+
ckpt = "sdxl_lightning_2step_unet.safetensors" # Use the correct ckpt for your step setting!
|
| 17 |
|
| 18 |
+
# Load model.
|
| 19 |
+
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
|
| 20 |
+
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
| 21 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
| 22 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
| 23 |
|
| 24 |
+
def generate_image(text):
|
| 25 |
|
| 26 |
+
image = pipe("krishna", num_inference_steps=2, guidance_scale=0).images[0]
|
| 27 |
+
|
| 28 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Create a Gradio interface
|
| 31 |
iface = gr.Interface(
|
| 32 |
+
fn=generate_image,
|
| 33 |
+
inputs=gr.inputs.Textbox(lines=5, label="Enter a description for the image"),
|
| 34 |
+
outputs="image",
|
| 35 |
+
title="Text to Image Generation",
|
| 36 |
+
description="Enter a text description and get an image.",
|
| 37 |
+
theme="compact"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Launch the Gradio app
|
| 41 |
iface.launch()
|