Spaces:
Runtime error
Runtime error
File size: 7,049 Bytes
efb6861 dc72d06 9a88db2 b4447cb 34f8aaa 9a88db2 3845902 c9ef435 588dca4 3845902 c9ef435 588dca4 c9ef435 ba78f27 efb6861 c9ef435 ba78f27 34f8aaa c9ef435 ba78f27 9a88db2 3845902 34f8aaa ba78f27 0df461a ba78f27 0df461a ba78f27 c9ef435 ba78f27 c9ef435 0df461a ba78f27 0df461a ba78f27 3845902 ba78f27 c9ef435 ba78f27 3845902 ba78f27 3845902 ba78f27 3845902 ba78f27 3845902 ba78f27 3845902 ba78f27 3845902 ba78f27 3845902 ba78f27 efb6861 dc72d06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
import os
import sys
# Apply compatibility patches first
try:
import compatibility_patches
except ImportError:
print("Warning: compatibility_patches not found")
# Print environment information
print("==== Environment Information ====")
print(f"Python version: {sys.version}")
print(f"Working directory: {os.getcwd()}")
print(f"Directory contents: {os.listdir('.')}")
# Import key packages and print versions
packages = {
"torch": None,
"transformers": None,
"diffusers": None,
"accelerate": None,
"einops": None,
"omegaconf": None,
"librosa": None
}
for package in packages.keys():
try:
module = __import__(package)
try:
packages[package] = module.__version__
print(f"{package}: {module.__version__}")
except AttributeError:
packages[package] = "Installed (version unknown)"
print(f"{package}: Installed (version unknown)")
except ImportError as e:
print(f"{package}: Not installed")
packages[package] = "Not installed"
# Create necessary directories
os.makedirs("assets", exist_ok=True)
os.makedirs("ckpts", exist_ok=True)
os.makedirs("outputs", exist_ok=True)
# Download example audio files if they don't exist
if not os.path.exists("assets/fire_crackling.wav") or not os.path.exists("assets/plastic_bag.wav"):
try:
from download_assets import download_gdrive_file
assets = {
"assets/fire_crackling.wav": "1vOAZcbkpo_hre2g26n--lUXdwbTQp22k",
"assets/plastic_bag.wav": "15igeDor7a47a-oluSCfO6GeUvFVl2ttb"
}
for path, file_id in assets.items():
if not os.path.exists(path):
download_gdrive_file(file_id, path)
except Exception as e:
print(f"Error downloading example audio files: {e}")
# Import required packages
import gradio as gr
# Import our controller
from controller import SonicDiffusionController
# Initialize controller
controller = SonicDiffusionController()
# Create the Gradio interface
with gr.Blocks(title="SonicDiffusion") as demo:
gr.Markdown("# SonicDiffusion - Audio-to-Image Generation")
gr.Markdown("Generate images conditioned on audio inputs using Stable Diffusion")
status_output = gr.Textbox(label="Status", value="System initialized. Start by checking dependencies and downloading assets.", lines=8)
with gr.Tab("1. Setup"):
with gr.Row():
with gr.Column():
check_deps_btn = gr.Button("Check Dependencies")
def format_deps():
deps = controller.check_dependencies()
return "\n".join([f"{pkg}: {vers}" for pkg, vers in deps.items()])
check_deps_btn.click(
fn=format_deps,
outputs=status_output
)
with gr.Column():
check_assets_btn = gr.Button("Check Assets")
def format_assets():
assets = controller.check_assets()
return "\n".join([f"{path}: {'✓' if exists else '✗'}" for path, exists in assets.items()])
check_assets_btn.click(
fn=format_assets,
outputs=status_output
)
download_assets_btn = gr.Button("Download Required Assets", variant="primary")
download_assets_btn.click(fn=controller.download_assets, outputs=status_output)
with gr.Tab("2. Generate"):
with gr.Row():
with gr.Column():
model_dropdown = gr.Dropdown(
label="Select Model",
choices=["Landscape Model", "Greatest Hits Model"],
value="Landscape Model"
)
load_model_btn = gr.Button("Load Selected Model", variant="primary")
load_model_btn.click(
fn=controller.load_model,
inputs=[model_dropdown],
outputs=status_output
)
prompt_input = gr.Textbox(
label="Prompt",
placeholder="Enter a descriptive prompt...",
value="a high quality photograph of a fantasy landscape"
)
# Use the preloaded example audio files
audio_dropdown = gr.Dropdown(
label="Select Example Audio",
choices=["assets/fire_crackling.wav", "assets/plastic_bag.wav", "Upload my own audio"],
value="assets/fire_crackling.wav"
)
audio_input = gr.Audio(
label="Or Upload Your Own Audio",
type="filepath",
sources=["upload", "microphone"],
visible=False
)
def toggle_audio_upload(choice):
return gr.update(visible=(choice == "Upload my own audio"))
audio_dropdown.change(
fn=toggle_audio_upload,
inputs=[audio_dropdown],
outputs=[audio_input]
)
with gr.Row():
cfg_scale = gr.Slider(
label="CFG Scale",
minimum=1.0,
maximum=20.0,
value=7.5,
step=0.5
)
steps = gr.Slider(
label="Steps",
minimum=20,
maximum=100,
value=50,
step=5
)
def prepare_audio_path(dropdown_choice, uploaded_audio):
if dropdown_choice == "Upload my own audio":
return uploaded_audio
else:
return dropdown_choice
generate_btn = gr.Button("Generate Image", variant="primary")
with gr.Column():
output_image = gr.Image(label="Generated Image", type="pil")
output_status = gr.Textbox(label="Generation Status", value="")
generate_btn.click(
fn=lambda p, d, u, c, s: (
controller.generate(p, prepare_audio_path(d, u), c, s),
"Generation completed"
),
inputs=[prompt_input, audio_dropdown, audio_input, cfg_scale, steps],
outputs=[output_image, output_status]
)
if __name__ == "__main__":
# Change the server parameters
demo.launch(server_name="0.0.0.0", share=True)
|