Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,50 +48,30 @@ def download_and_split_image(url):
|
|
| 48 |
return [save_image(i) for i in images]
|
| 49 |
|
| 50 |
def niji_api(prompt):
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
try:
|
| 57 |
-
response = requests.
|
| 58 |
-
response.raise_for_status()
|
| 59 |
except requests.exceptions.RequestException as e:
|
| 60 |
-
logger.
|
| 61 |
-
|
| 62 |
data = response.json()
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
except requests.exceptions.RequestException as e:
|
| 71 |
-
logger.warning(f"Failure in getting message response")
|
| 72 |
-
continue
|
| 73 |
-
|
| 74 |
-
data = response.json()
|
| 75 |
-
progress = data.get('progress', 0)
|
| 76 |
-
|
| 77 |
-
if progress_image_url:= data.get('progressImageUrl'):
|
| 78 |
-
images.extend([(img, f"{progress}% done") for img in download_and_split_image(progress_image_url)])
|
| 79 |
-
time.sleep(1)
|
| 80 |
-
|
| 81 |
-
# Process the final image urls
|
| 82 |
-
image_url = data['response']['imageUrl']
|
| 83 |
-
images.extend([(img, f"image {idx+1}/4") for idx, img in enumerate(download_and_split_image(image_url))])
|
| 84 |
-
|
| 85 |
-
t = threading.Timer(180, function=function)
|
| 86 |
-
t.start()
|
| 87 |
-
t.join()
|
| 88 |
-
|
| 89 |
-
if t.is_alive():
|
| 90 |
-
# Thread is still executing, raise a TimeoutError
|
| 91 |
-
t.cancel()
|
| 92 |
-
raise TimeoutError("Operation timed out after 3 minutes")
|
| 93 |
-
|
| 94 |
-
return images
|
| 95 |
|
| 96 |
with gr.Blocks() as demo:
|
| 97 |
gr.HTML('''
|
|
|
|
| 48 |
return [save_image(i) for i in images]
|
| 49 |
|
| 50 |
def niji_api(prompt):
|
| 51 |
+
try:
|
| 52 |
+
response = requests.post(fetapi, headers={'Content-Type': 'application/json'}, data=json.dumps({'msg': prompt}))
|
| 53 |
+
response.raise_for_status() # Check for HTTP errors.
|
| 54 |
+
except requests.exceptions.RequestException as e:
|
| 55 |
+
logger.error(f"Failed to make POST request")
|
| 56 |
+
raise ValueError("Invalid Response")
|
| 57 |
+
data = response.json()
|
| 58 |
+
message_id = data['messageId']
|
| 59 |
+
progress = 0
|
| 60 |
+
while progress < 100:
|
| 61 |
try:
|
| 62 |
+
response = requests.get(f'{odnapi}/message/{message_id}', headers={'Authorization': auth_token})
|
| 63 |
+
response.raise_for_status()
|
| 64 |
except requests.exceptions.RequestException as e:
|
| 65 |
+
logger.warning(f"Failure in getting message response")
|
| 66 |
+
continue
|
| 67 |
data = response.json()
|
| 68 |
+
progress = data.get('progress', 0)
|
| 69 |
+
if progress_image_url:= data.get('progressImageUrl'):
|
| 70 |
+
yield [(img, f"{progress}% done") for img in download_and_split_image(progress_image_url)]
|
| 71 |
+
time.sleep(1)
|
| 72 |
+
# Process the final image urls
|
| 73 |
+
image_url = data['response']['imageUrl']
|
| 74 |
+
yield [(img, f"image {idx+1}/4") for idx, img in enumerate(download_and_split_image(image_url))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
with gr.Blocks() as demo:
|
| 77 |
gr.HTML('''
|