CosmoAI commited on
Commit
a43ca38
·
verified ·
1 Parent(s): 31ed165

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -36
app.py CHANGED
@@ -1,39 +1,63 @@
1
- import streamlit as st
2
- import torch
3
- from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
4
- from huggingface_hub import hf_hub_download
5
- from safetensors.torch import load_file
6
-
7
-
8
-
9
- # Model Path/Repo Information
10
- base = "stabilityai/stable-diffusion-xl-base-1.0"
11
- repo = "ByteDance/SDXL-Lightning"
12
- ckpt = "sdxl_lightning_4step_unet.safetensors"
13
-
14
- # Load model (Executed only once for efficiency)
15
- @st.cache_resource
16
- def load_sdxl_pipeline():
17
- unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cpu", torch.float32)
18
- unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cpu"))
19
- pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float32, variant="fp16").to("cpu")
20
- pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
21
- return pipe
22
-
23
-
24
- # Streamlit UI
25
- st.title("Image Generation")
26
- prompt = st.text_input("Enter your image prompt:")
27
-
28
- if st.button("Generate Image"):
29
- if not prompt:
30
- st.warning("Please enter a prompt.")
31
- else:
32
- pipe = load_sdxl_pipeline() # Load the pipeline from cache
33
- with torch.no_grad():
34
- image = pipe(prompt).images[0]
35
-
36
- st.image(image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
 
39
 
 
1
+ import subprocess
2
+
3
+ def run_terminal_command(command):
4
+ try:
5
+ # Run the terminal command and capture its output
6
+ output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
7
+ return output.decode("utf-8") # Decode bytes to string
8
+ except subprocess.CalledProcessError as e:
9
+ # Handle errors if the command fails
10
+ return f"Error: {e.output.decode('utf-8')}"
11
+
12
+ # Example command: list files in the current directory
13
+ command = "ls"
14
+ output = run_terminal_command(command)
15
+ print(output)
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ # import streamlit as st
26
+ # import torch
27
+ # from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
28
+ # from huggingface_hub import hf_hub_download
29
+ # from safetensors.torch import load_file
30
+
31
+
32
+
33
+ # # Model Path/Repo Information
34
+ # base = "stabilityai/stable-diffusion-xl-base-1.0"
35
+ # repo = "ByteDance/SDXL-Lightning"
36
+ # ckpt = "sdxl_lightning_4step_unet.safetensors"
37
+
38
+ # # Load model (Executed only once for efficiency)
39
+ # @st.cache_resource
40
+ # def load_sdxl_pipeline():
41
+ # unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cpu", torch.float32)
42
+ # unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cpu"))
43
+ # pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float32, variant="fp16").to("cpu")
44
+ # pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
45
+ # return pipe
46
+
47
+
48
+ # # Streamlit UI
49
+ # st.title("Image Generation")
50
+ # prompt = st.text_input("Enter your image prompt:")
51
+
52
+ # if st.button("Generate Image"):
53
+ # if not prompt:
54
+ # st.warning("Please enter a prompt.")
55
+ # else:
56
+ # pipe = load_sdxl_pipeline() # Load the pipeline from cache
57
+ # with torch.no_grad():
58
+ # image = pipe(prompt).images[0]
59
+
60
+ # st.image(image)
61
 
62
 
63