Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,103 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
-
|
| 5 |
-
zero = torch.Tensor([0]).cuda()
|
| 6 |
-
print(zero.device) # <-- 'cpu' 🤔
|
| 7 |
|
| 8 |
@spaces.GPU
|
| 9 |
def greet(n):
|
| 10 |
print(zero.device) # <-- 'cuda:0' 🤗
|
| 11 |
return f"Hello {zero + n} Tensor"
|
| 12 |
|
| 13 |
-
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
| 14 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
+
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
@spaces.GPU
|
| 7 |
def greet(n):
|
| 8 |
print(zero.device) # <-- 'cuda:0' 🤗
|
| 9 |
return f"Hello {zero + n} Tensor"
|
| 10 |
|
| 11 |
+
#demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
| 12 |
+
#demo.launch()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
import gradio as gr
|
| 16 |
+
|
| 17 |
+
IMAGE_FOLDER = "./images" # Change this to your folder path
|
| 18 |
+
|
| 19 |
+
def get_image_list(folder):
|
| 20 |
+
if not os.path.exists(folder):
|
| 21 |
+
return []
|
| 22 |
+
valid_extensions = (".png", ".jpg", ".jpeg", ".webp", ".gif")
|
| 23 |
+
return [f for f in os.listdir(folder) if f.lower().endswith(valid_extensions)]
|
| 24 |
+
|
| 25 |
+
image_files = get_image_list(IMAGE_FOLDER)
|
| 26 |
+
|
| 27 |
+
def load_image(selected_file):
|
| 28 |
+
if not selected_file:
|
| 29 |
+
return None
|
| 30 |
+
return os.path.join(IMAGE_FOLDER, selected_file)
|
| 31 |
+
|
| 32 |
+
# Generation pipeline function using both the source image and text prompt
|
| 33 |
+
def process_and_generate(selected_file, prompt):
|
| 34 |
+
if not selected_file:
|
| 35 |
+
return None, "Please select an input image first."
|
| 36 |
+
if not prompt:
|
| 37 |
+
return None, "Please enter a text prompt."
|
| 38 |
+
|
| 39 |
+
input_path = os.path.join(IMAGE_FOLDER, selected_file)
|
| 40 |
+
|
| 41 |
+
# -------------------------------------------------------------
|
| 42 |
+
# PLACEHOLDER: Insert your Multi-ControlNet / SD pipeline here
|
| 43 |
+
# e.g., output = pipeline(image=input_path, prompt=prompt)
|
| 44 |
+
# -------------------------------------------------------------
|
| 45 |
+
|
| 46 |
+
# For demonstration, returning the input image path
|
| 47 |
+
generated_output = input_path
|
| 48 |
+
|
| 49 |
+
return generated_output, f"Generated matching prompt: '{prompt}'"
|
| 50 |
+
|
| 51 |
+
with gr.Blocks() as demo:
|
| 52 |
+
gr.Markdown("# Guided Image Generation Pipeline")
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
# Column 1: Source Image Selection
|
| 56 |
+
with gr.Column():
|
| 57 |
+
gr.Markdown("### 1. Source Image")
|
| 58 |
+
image_dropdown = gr.Dropdown(
|
| 59 |
+
choices=image_files,
|
| 60 |
+
label="Select Input Image from Folder",
|
| 61 |
+
value=image_files if image_files else None
|
| 62 |
+
)
|
| 63 |
+
input_preview = gr.Image(type="filepath", label="Input Preview")
|
| 64 |
+
|
| 65 |
+
# Column 2: Prompt Engineering & Execution
|
| 66 |
+
with gr.Column():
|
| 67 |
+
gr.Markdown("### 2. Generation Settings")
|
| 68 |
+
prompt_input = gr.Textbox(
|
| 69 |
+
label="Text Prompt",
|
| 70 |
+
placeholder="Describe modifications, styles, or Canny/Depth map directions...",
|
| 71 |
+
lines=3
|
| 72 |
+
)
|
| 73 |
+
generate_btn = gr.Button("Generate Image", variant="primary")
|
| 74 |
+
|
| 75 |
+
# Column 3: Output Visualization
|
| 76 |
+
with gr.Column():
|
| 77 |
+
gr.Markdown("### 3. Pipeline Output")
|
| 78 |
+
output_image = gr.Image(type="filepath", label="Generated Output")
|
| 79 |
+
status_text = gr.Textbox(label="Status", interactive=False)
|
| 80 |
+
|
| 81 |
+
# Core event binds
|
| 82 |
+
image_dropdown.change(
|
| 83 |
+
fn=load_image,
|
| 84 |
+
inputs=image_dropdown,
|
| 85 |
+
outputs=input_preview
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
generate_btn.click(
|
| 89 |
+
fn=process_and_generate,
|
| 90 |
+
inputs=[image_dropdown, prompt_input],
|
| 91 |
+
outputs=[output_image, status_text]
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Initial state setup
|
| 95 |
+
if image_files:
|
| 96 |
+
demo.load(
|
| 97 |
+
fn=load_image,
|
| 98 |
+
inputs=image_dropdown,
|
| 99 |
+
outputs=input_preview
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
if __name__ == "__main__":
|
| 103 |
+
demo.launch()
|