Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -73,6 +73,44 @@ def send_image2image_request(image, ratio, style, uuid_value, token):
|
|
73 |
else:
|
74 |
return f"Error: {response.status_code} - {response.text}"
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
# Function to get the Upload URL from Firebase
|
77 |
def get_upload_url(uuid_value):
|
78 |
# The URL to send the request to
|
@@ -159,6 +197,20 @@ def create_interface():
|
|
159 |
# Bind the image-to-image function to the interface
|
160 |
img_submit_button = gr.Button("Generate Image")
|
161 |
img_submit_button.click(send_image2image_request, inputs=[img_url, img_ratio, img_style, img_uuid, img_token], outputs=img_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
with gr.Tab("Get Upload URL"):
|
164 |
# Inputs for Get Upload URL
|
|
|
73 |
else:
|
74 |
return f"Error: {response.status_code} - {response.text}"
|
75 |
|
76 |
+
# Function for Image-to-Image (Send POST request with an image and other parameters)
|
77 |
+
def send_inpaint2image_request(image, mask, prompt, ratio, uuid_value, token):
|
78 |
+
# Access the URL from Secrets (Private)
|
79 |
+
url = os.getenv('API_URL_IMAGE') # Secret variable for the URL
|
80 |
+
if not url:
|
81 |
+
return "Error: API URL not set in environment secrets."
|
82 |
+
|
83 |
+
# Define the headers with the required values
|
84 |
+
headers = {
|
85 |
+
"Uid": uuid_value, # Using the provided UUID
|
86 |
+
"Versioncode": "16701",
|
87 |
+
"Accept-Version": "v1",
|
88 |
+
"Token": token, # Replace with the actual token
|
89 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
90 |
+
}
|
91 |
+
|
92 |
+
# Define the values to be sent in the POST request
|
93 |
+
data = {
|
94 |
+
"is_translate": "1",
|
95 |
+
"is_first": "true",
|
96 |
+
"image_name": image,
|
97 |
+
"mask_name":mask,
|
98 |
+
"prompt": prompt,
|
99 |
+
"ratio": ratio,
|
100 |
+
"is_img2img": "1"
|
101 |
+
}
|
102 |
+
|
103 |
+
if style and style != "0":
|
104 |
+
data["style_id"] = style
|
105 |
+
|
106 |
+
response = requests.post(url, headers=headers, data=data)
|
107 |
+
|
108 |
+
# Return the response text or any relevant information
|
109 |
+
if response.status_code == 200:
|
110 |
+
return response.text
|
111 |
+
else:
|
112 |
+
return f"Error: {response.status_code} - {response.text}"
|
113 |
+
|
114 |
# Function to get the Upload URL from Firebase
|
115 |
def get_upload_url(uuid_value):
|
116 |
# The URL to send the request to
|
|
|
197 |
# Bind the image-to-image function to the interface
|
198 |
img_submit_button = gr.Button("Generate Image")
|
199 |
img_submit_button.click(send_image2image_request, inputs=[img_url, img_ratio, img_style, img_uuid, img_token], outputs=img_output)
|
200 |
+
|
201 |
+
with gr.Tab("Inpaint Image"):
|
202 |
+
# Inputs for Inpaint-to-Image
|
203 |
+
img_url = gr.Textbox(label="URL")
|
204 |
+
img_mask = gr.Textbox(label="Mask URL")
|
205 |
+
img_prompt = gr.Textbox(label="Prompt")
|
206 |
+
img_ratio = gr.Textbox(label="Ratio")
|
207 |
+
img_uuid = gr.Textbox(label="UUID ID") # Default UUID
|
208 |
+
img_token = gr.Textbox(label="Token ID") # Password type for token
|
209 |
+
img_output = gr.Textbox() # Output for image-to-image response
|
210 |
+
|
211 |
+
# Bind the image-to-image function to the interface
|
212 |
+
img_submit_button = gr.Button("Generate Image")
|
213 |
+
img_submit_button.click(send_inpaint2image_request, inputs=[img_url, img_mask, img_prompt, img_ratio, img_uuid, img_token], outputs=img_output)
|
214 |
|
215 |
with gr.Tab("Get Upload URL"):
|
216 |
# Inputs for Get Upload URL
|