File size: 1,484 Bytes
22f252d f54ff87 22f252d f54ff87 22f252d f54ff87 22f252d f54ff87 22f252d f54ff87 22f252d f44adf2 f54ff87 22f252d f54ff87 22f252d c302ef4 |
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 |
import gradio as gr
import subprocess
import os
import shutil
from PIL import Image
def generate_sketch(concept, temperature):
save_path = "results/test"
command = [
"python", "sketch/gen_sketch.py",
"--concept_to_draw", concept,
"--temperature", str(temperature),
"--path2save", save_path
]
try:
subprocess.run(command, check=True)
img_path = os.path.join(save_path, concept, f"{concept}_canvas.png")
if not os.path.exists(img_path):
return f"Sketch generation succeeded but image not found: {img_path}", None
return "Sketch generated successfully!", img_path
except subprocess.CalledProcessError as e:
return f"Sketch generation failed: {str(e)}", None
def ui():
with gr.Blocks() as demo:
gr.Markdown("## 🎨 Sketch Generator")
with gr.Row():
concept = gr.Textbox(label="What Should I sketch", placeholder="e.g. Taj Mahal")
temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.3, step=0.05, label="Temperature")
generate_btn = gr.Button("Generate Sketch")
status = gr.Textbox(label="Status")
output_image = gr.Image(label="Generated Sketch", type="filepath")
generate_btn.click(
fn=generate_sketch,
inputs=[concept, temperature],
outputs=[status, output_image]
)
return demo
if __name__ == "__main__":
ui().launch(share=True)
|