|
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) |
|
|