Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ from gradio_client import Client
|
|
3 |
import os
|
4 |
import logging
|
5 |
import requests
|
|
|
|
|
|
|
6 |
|
7 |
# 로깅 설정
|
8 |
logging.basicConfig(level=logging.INFO)
|
@@ -13,10 +16,17 @@ api_client = Client("http://211.233.58.202:7960/")
|
|
13 |
# Zapier 웹훅 URL
|
14 |
WEBHOOK_URL = "https://hooks.zapier.com/hooks/catch/14523965/264pyhj/"
|
15 |
|
16 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
payload = {
|
18 |
"prompt": prompt,
|
19 |
-
"
|
20 |
}
|
21 |
try:
|
22 |
response = requests.post(WEBHOOK_URL, json=payload)
|
@@ -47,13 +57,14 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
47 |
# 결과 확인 및 처리
|
48 |
if isinstance(result, tuple) and len(result) >= 1:
|
49 |
image_path = result[0]
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
# 웹훅으로 데이터 전송
|
54 |
-
send_to_webhook(message,
|
55 |
|
56 |
-
return
|
57 |
else:
|
58 |
raise ValueError("Unexpected API response format")
|
59 |
except Exception as e:
|
|
|
3 |
import os
|
4 |
import logging
|
5 |
import requests
|
6 |
+
from PIL import Image
|
7 |
+
import io
|
8 |
+
import base64
|
9 |
|
10 |
# 로깅 설정
|
11 |
logging.basicConfig(level=logging.INFO)
|
|
|
16 |
# Zapier 웹훅 URL
|
17 |
WEBHOOK_URL = "https://hooks.zapier.com/hooks/catch/14523965/264pyhj/"
|
18 |
|
19 |
+
def convert_webp_to_png_base64(image_path):
|
20 |
+
with Image.open(image_path) as img:
|
21 |
+
buffered = io.BytesIO()
|
22 |
+
img.convert("RGB").save(buffered, format="PNG")
|
23 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
24 |
+
return f"data:image/png;base64,{img_str}"
|
25 |
+
|
26 |
+
def send_to_webhook(prompt, image_data):
|
27 |
payload = {
|
28 |
"prompt": prompt,
|
29 |
+
"image_data": image_data
|
30 |
}
|
31 |
try:
|
32 |
response = requests.post(WEBHOOK_URL, json=payload)
|
|
|
57 |
# 결과 확인 및 처리
|
58 |
if isinstance(result, tuple) and len(result) >= 1:
|
59 |
image_path = result[0]
|
60 |
+
|
61 |
+
# WebP를 PNG로 변환하고 base64 인코딩
|
62 |
+
image_data = convert_webp_to_png_base64(image_path)
|
63 |
|
64 |
# 웹훅으로 데이터 전송
|
65 |
+
send_to_webhook(message, image_data)
|
66 |
|
67 |
+
return image_path # Gradio 인터페이스를 위해 원본 이미지 경로 반환
|
68 |
else:
|
69 |
raise ValueError("Unexpected API response format")
|
70 |
except Exception as e:
|