Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,63 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
st
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|