Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
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,17 +14,10 @@ api_client = Client("http://211.233.58.202:7960/")
|
|
16 |
# Zapier 웹훅 URL
|
17 |
WEBHOOK_URL = "https://hooks.zapier.com/hooks/catch/14523965/264pyhj/"
|
18 |
|
19 |
-
def
|
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 |
-
"
|
30 |
}
|
31 |
try:
|
32 |
response = requests.post(WEBHOOK_URL, json=payload)
|
@@ -57,14 +48,13 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
57 |
# 결과 확인 및 처리
|
58 |
if isinstance(result, tuple) and len(result) >= 1:
|
59 |
image_path = result[0]
|
60 |
-
|
61 |
-
|
62 |
-
image_data = convert_webp_to_png_base64(image_path)
|
63 |
|
64 |
# 웹훅으로 데이터 전송
|
65 |
-
send_to_webhook(message,
|
66 |
|
67 |
-
return
|
68 |
else:
|
69 |
raise ValueError("Unexpected API response format")
|
70 |
except Exception as e:
|
@@ -72,6 +62,7 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
72 |
return "Failed to generate image due to an error."
|
73 |
|
74 |
|
|
|
75 |
css = """
|
76 |
footer {
|
77 |
visibility: hidden;
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
from gradio_client import Client
|
4 |
import os
|
5 |
import logging
|
6 |
import requests
|
|
|
|
|
|
|
7 |
|
8 |
# 로깅 설정
|
9 |
logging.basicConfig(level=logging.INFO)
|
|
|
14 |
# Zapier 웹훅 URL
|
15 |
WEBHOOK_URL = "https://hooks.zapier.com/hooks/catch/14523965/264pyhj/"
|
16 |
|
17 |
+
def send_to_webhook(prompt, image_url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
payload = {
|
19 |
"prompt": prompt,
|
20 |
+
"image_url": image_url
|
21 |
}
|
22 |
try:
|
23 |
response = requests.post(WEBHOOK_URL, json=payload)
|
|
|
48 |
# 결과 확인 및 처리
|
49 |
if isinstance(result, tuple) and len(result) >= 1:
|
50 |
image_path = result[0]
|
51 |
+
# 이미지 URL 생성 (실제 서버 URL로 변경 필요)
|
52 |
+
image_url = f"http://211.233.58.202:7960/file={image_path}"
|
|
|
53 |
|
54 |
# 웹훅으로 데이터 전송
|
55 |
+
send_to_webhook(message, image_url)
|
56 |
|
57 |
+
return image_url
|
58 |
else:
|
59 |
raise ValueError("Unexpected API response format")
|
60 |
except Exception as e:
|
|
|
62 |
return "Failed to generate image due to an error."
|
63 |
|
64 |
|
65 |
+
|
66 |
css = """
|
67 |
footer {
|
68 |
visibility: hidden;
|