Spaces:
Sleeping
Sleeping
VikramSingh178
commited on
Commit
•
3d420f6
1
Parent(s):
d34e3ca
Upload folder using huggingface_hub
Browse files- README.md +2 -8
- __pycache__/ui.cpython-310.pyc +0 -0
- __pycache__/ui.cpython-311.pyc +0 -0
- ui.py +113 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title: PicPilot
|
3 |
-
|
4 |
-
colorFrom: pink
|
5 |
-
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.36.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: PicPilot-UI
|
3 |
+
app_file: ui.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 4.36.1
|
|
|
|
|
6 |
---
|
|
|
|
__pycache__/ui.cpython-310.pyc
ADDED
Binary file (3.72 kB). View file
|
|
__pycache__/ui.cpython-311.pyc
ADDED
Binary file (8 kB). View file
|
|
ui.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from pydantic import BaseModel
|
4 |
+
from diffusers.utils import load_image
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
sdxl_inference_endpoint = 'https://vikramsingh178-picpilot-server.hf.space/api/v1/product-diffusion/sdxl_v0_lora_inference'
|
10 |
+
sdxl_batch_inference_endpoint = 'https://vikramsingh178-picpilot-server.hf.space/api/v1/product-diffusion/sdxl_v0_lora_inference/batch'
|
11 |
+
kandinsky_inpainting_inference = 'https://vikramsingh178-picpilot-server.hf.space/api/v1/product-diffusion/kandinskyv2.2_inpainting'
|
12 |
+
|
13 |
+
# Define the InpaintingRequest model
|
14 |
+
class InputRequest(BaseModel):
|
15 |
+
prompt: str
|
16 |
+
num_inference_steps: int
|
17 |
+
guidance_scale: float
|
18 |
+
negative_prompt: str
|
19 |
+
num_images: int
|
20 |
+
mode: str
|
21 |
+
|
22 |
+
class InpaintingRequest(BaseModel):
|
23 |
+
prompt: str
|
24 |
+
negative_prompt: str
|
25 |
+
num_inference_steps: int
|
26 |
+
strength: float
|
27 |
+
guidance_scale: float
|
28 |
+
mode: str
|
29 |
+
|
30 |
+
async def generate_sdxl_lora_image(prompt, negative_prompt, num_inference_steps, guidance_scale, num_images, mode):
|
31 |
+
# Prepare the payload for SDXL LORA API
|
32 |
+
payload = InputRequest(
|
33 |
+
prompt=prompt,
|
34 |
+
negative_prompt=negative_prompt,
|
35 |
+
num_inference_steps=num_inference_steps,
|
36 |
+
guidance_scale=guidance_scale,
|
37 |
+
num_images=num_images,
|
38 |
+
mode=mode
|
39 |
+
).dict()
|
40 |
+
|
41 |
+
response = requests.post(sdxl_inference_endpoint, json=payload)
|
42 |
+
response = response.json()
|
43 |
+
url = response['url']
|
44 |
+
image = load_image(url)
|
45 |
+
return image
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
def generate_outpainting(prompt, negative_prompt, num_inference_steps, strength, guidance_scale, mode, image):
|
50 |
+
# Convert the image to bytes
|
51 |
+
img_byte_arr = BytesIO()
|
52 |
+
image.save(img_byte_arr, format='PNG')
|
53 |
+
img_byte_arr = img_byte_arr.getvalue()
|
54 |
+
|
55 |
+
# Prepare the payload for multipart/form-data
|
56 |
+
files = {
|
57 |
+
'image': ('image.png', img_byte_arr, 'image/png'),
|
58 |
+
'prompt': (None, prompt),
|
59 |
+
'negative_prompt': (None, negative_prompt),
|
60 |
+
'num_inference_steps': (None, str(num_inference_steps)),
|
61 |
+
'strength': (None, str(strength)),
|
62 |
+
'guidance_scale': (None, str(guidance_scale)),
|
63 |
+
'mode': (None, mode)
|
64 |
+
}
|
65 |
+
|
66 |
+
response = requests.post(kandinsky_inpainting_inference, files=files)
|
67 |
+
response.raise_for_status()
|
68 |
+
response = response.json()
|
69 |
+
url = response['url']
|
70 |
+
image = load_image(url)
|
71 |
+
return image
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
with gr.Blocks(theme='VikramSingh178/Webui-Theme') as demo:
|
76 |
+
with gr.Tab("SdxL-Lora"):
|
77 |
+
with gr.Row():
|
78 |
+
with gr.Column():
|
79 |
+
with gr.Group():
|
80 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
|
81 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
|
82 |
+
num_inference_steps = gr.Slider(minimum=1, maximum=1000, step=1, value=20, label="Inference Steps")
|
83 |
+
guidance_scale = gr.Slider(minimum=1.0, maximum=10.0, step=0.1, value=7.5, label="Guidance Scale")
|
84 |
+
num_images = gr.Slider(minimum=1, maximum=10, step=1, value=1, label="Number of Images")
|
85 |
+
mode = gr.Dropdown(choices=["s3_json", "b64_json"], value="s3_json", label="Mode")
|
86 |
+
generate_button = gr.Button("Generate Image",variant='primary')
|
87 |
+
|
88 |
+
with gr.Column(scale=1):
|
89 |
+
|
90 |
+
image_preview = gr.Image(label="Generated Image",show_download_button=True,show_share_button=True,container=True)
|
91 |
+
generate_button.click(generate_sdxl_lora_image, inputs=[prompt, negative_prompt, num_inference_steps, guidance_scale, num_images, mode], outputs=[image_preview])
|
92 |
+
|
93 |
+
with gr.Tab("Generate AI Background"):
|
94 |
+
with gr.Row():
|
95 |
+
with gr.Column():
|
96 |
+
with gr.Group():
|
97 |
+
image_input = gr.Image(type="pil", label="Upload Image")
|
98 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
|
99 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
|
100 |
+
num_inference_steps = gr.Slider(minimum=1, maximum=500, step=1, value=20, label="Inference Steps")
|
101 |
+
guidance_scale = gr.Slider(minimum=1.0, maximum=10.0, step=0.1, value=7.5, label="Guidance Scale")
|
102 |
+
strength = gr.Slider(minimum=0.1, maximum=1, step=0.1, value=1, label="Strength")
|
103 |
+
mode = gr.Dropdown(choices=["s3_json", "b64_json"], value="s3_json", label="Mode")
|
104 |
+
generate_button = gr.Button("Generate Background", variant='primary')
|
105 |
+
|
106 |
+
with gr.Column(scale=1):
|
107 |
+
|
108 |
+
image_preview = gr.Image(label="Image", show_download_button=True, show_share_button=True, container=True)
|
109 |
+
generate_button.click(generate_outpainting, inputs=[prompt, negative_prompt, num_inference_steps, strength, guidance_scale, mode, image_input], outputs=[image_preview])
|
110 |
+
|
111 |
+
demo.launch()
|
112 |
+
|
113 |
+
|