Spaces:
Sleeping
Sleeping
Create app.py
#1
by sohaibdevv - opened
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import io
|
| 5 |
+
|
| 6 |
+
# Initialize the client (Uses Hugging Face's free inference API)
|
| 7 |
+
client = InferenceClient("lllyasviel/sd-controlnet-scribble")
|
| 8 |
+
|
| 9 |
+
def generate_image(sketch, prompt):
|
| 10 |
+
if sketch is None:
|
| 11 |
+
return None
|
| 12 |
+
|
| 13 |
+
# The model expects a prompt to guide the style
|
| 14 |
+
full_prompt = f"Professional photography, high quality, realistic, {prompt}"
|
| 15 |
+
|
| 16 |
+
# Generate the image
|
| 17 |
+
# Note: 'sketch' from Gradio is a dictionary with 'composite' or a PIL image
|
| 18 |
+
image = client.image_to_image(sketch, prompt=full_prompt)
|
| 19 |
+
return image
|
| 20 |
+
|
| 21 |
+
# Build a stylish UI
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# 🎨 Sketch-to-Photo AI")
|
| 24 |
+
gr.Markdown("Draw something simple on the left, type what it is, and watch it turn into a photo!")
|
| 25 |
+
|
| 26 |
+
with gr.Row():
|
| 27 |
+
with gr.Column():
|
| 28 |
+
# The Sketchpad input
|
| 29 |
+
input_sketch = gr.Sketchpad(type="pil", label="Draw Here")
|
| 30 |
+
prompt_input = gr.Textbox(placeholder="What did you draw? (e.g., 'A sunset over mountains')", label="Description")
|
| 31 |
+
btn = gr.Button("Magic Generate ✨")
|
| 32 |
+
|
| 33 |
+
with gr.Column():
|
| 34 |
+
output_image = gr.Image(label="AI Result")
|
| 35 |
+
|
| 36 |
+
btn.click(fn=generate_image, inputs=[input_sketch, prompt_input], outputs=output_image)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|