Spaces:
Running
Running
Alex
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -76,6 +76,46 @@ def send_image2image_request(image, ratio, style, uuid_value, token, prompt):
|
|
76 |
else:
|
77 |
return f"Error: {response.status_code} - {response.text}"
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# Function for Image-to-Image (Send POST request with an image and other parameters)
|
80 |
def send_enhance_request(image, uuid_value, token):
|
81 |
# Access the URL from Secrets (Private)
|
@@ -304,13 +344,28 @@ def create_interface():
|
|
304 |
img_style = gr.Textbox(label="Style ID")
|
305 |
img_uuid = gr.Textbox(label="UUID ID") # Default UUID
|
306 |
img_token = gr.Textbox(label="Token ID") # Password type for token
|
307 |
-
|
308 |
img_output = gr.Textbox() # Output for image-to-image response
|
309 |
|
310 |
|
311 |
# Bind the image-to-image function to the interface
|
312 |
img_submit_button = gr.Button("Generate Image")
|
313 |
-
img_submit_button.click(send_image2image_request, inputs=[img_url, img_ratio, img_style, img_uuid, img_token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
with gr.Tab("Inpaint Image"):
|
316 |
# Inputs for Inpaint-to-Image
|
|
|
76 |
else:
|
77 |
return f"Error: {response.status_code} - {response.text}"
|
78 |
|
79 |
+
# Function for Image-to-Image (Send POST request with an image and other parameters)
|
80 |
+
def send_line2image_request(image, ratio, style, uuid_value, token, prompt):
|
81 |
+
# Access the URL from Secrets (Private)
|
82 |
+
url = os.getenv('API_URL_LINE') # Secret variable for the URL
|
83 |
+
if not url:
|
84 |
+
return "Error: API URL not set in environment secrets."
|
85 |
+
|
86 |
+
# Define the headers with the required values
|
87 |
+
headers = {
|
88 |
+
"Uid": uuid_value, # Using the provided UUID
|
89 |
+
"Versioncode": "16701",
|
90 |
+
"Accept-Version": "v1",
|
91 |
+
"Token": token, # Replace with the actual token
|
92 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
93 |
+
}
|
94 |
+
|
95 |
+
# Define the values to be sent in the POST request
|
96 |
+
data = {
|
97 |
+
"is_translate": "1",
|
98 |
+
"is_first": "true",
|
99 |
+
"ratio": ratio,
|
100 |
+
"denoising_strength": "50",
|
101 |
+
"image_name": image,
|
102 |
+
"is_img2img": "1"
|
103 |
+
}
|
104 |
+
|
105 |
+
if prompt and prompt != "0":
|
106 |
+
data["prompt"] = prompt
|
107 |
+
|
108 |
+
if style and style != "0":
|
109 |
+
data["style_id"] = style
|
110 |
+
|
111 |
+
response = requests.post(url, headers=headers, data=data)
|
112 |
+
|
113 |
+
# Return the response text or any relevant information
|
114 |
+
if response.status_code == 200:
|
115 |
+
return response.text
|
116 |
+
else:
|
117 |
+
return f"Error: {response.status_code} - {response.text}"
|
118 |
+
|
119 |
# Function for Image-to-Image (Send POST request with an image and other parameters)
|
120 |
def send_enhance_request(image, uuid_value, token):
|
121 |
# Access the URL from Secrets (Private)
|
|
|
344 |
img_style = gr.Textbox(label="Style ID")
|
345 |
img_uuid = gr.Textbox(label="UUID ID") # Default UUID
|
346 |
img_token = gr.Textbox(label="Token ID") # Password type for token
|
347 |
+
|
348 |
img_output = gr.Textbox() # Output for image-to-image response
|
349 |
|
350 |
|
351 |
# Bind the image-to-image function to the interface
|
352 |
img_submit_button = gr.Button("Generate Image")
|
353 |
+
img_submit_button.click(send_image2image_request, inputs=[img_url, img_ratio, img_style, img_uuid, img_token], outputs=img_output)
|
354 |
+
|
355 |
+
with gr.Tab("Line to Image"):
|
356 |
+
# Inputs for Image-to-Image
|
357 |
+
line_url = gr.Textbox(label="URL")
|
358 |
+
line_ratio = gr.Textbox(label="Ratio")
|
359 |
+
line_style = gr.Textbox(label="Style ID")
|
360 |
+
line_uuid = gr.Textbox(label="UUID ID") # Default UUID
|
361 |
+
line_token = gr.Textbox(label="Token ID") # Password type for token
|
362 |
+
lineg_prompt = gr.Textbox(label="img_prompt ID") # Password type for token
|
363 |
+
line_output = gr.Textbox() # Output for image-to-image response
|
364 |
+
|
365 |
+
|
366 |
+
# Bind the image-to-image function to the interface
|
367 |
+
line_submit_button = gr.Button("Generate Image")
|
368 |
+
line_submit_button.click(send_line2image_request, inputs=[line_url, line_ratio, line_style, line_uuid, line_token, line_prompt], outputs=line_output)
|
369 |
|
370 |
with gr.Tab("Inpaint Image"):
|
371 |
# Inputs for Inpaint-to-Image
|