Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import requests
|
|
6 |
from PIL import Image
|
7 |
import io
|
8 |
import base64
|
|
|
9 |
|
10 |
# 로깅 설정
|
11 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
@@ -18,7 +19,7 @@ api_client = Client("http://211.233.58.202:7960/")
|
|
18 |
WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY0MDYzMTA0MzE1MjZlNTUzYzUxM2Ei_pc"
|
19 |
|
20 |
# Imgur 클라이언트 ID
|
21 |
-
IMGUR_CLIENT_ID = "
|
22 |
|
23 |
def upload_to_imgur(image_data):
|
24 |
try:
|
@@ -48,65 +49,12 @@ def upload_to_imgur(image_data):
|
|
48 |
|
49 |
return response.json()['data']['link']
|
50 |
except Exception as e:
|
51 |
-
logger.error(f"Failed to upload image to Imgur: {e}")
|
|
|
52 |
if hasattr(e, 'response'):
|
53 |
logger.error(f"Response content: {e.response.text}")
|
54 |
return None
|
55 |
|
56 |
-
def send_to_webhook(prompt, image_url):
|
57 |
-
payload = {
|
58 |
-
"prompt": prompt,
|
59 |
-
"image": image_url
|
60 |
-
}
|
61 |
-
try:
|
62 |
-
response = requests.post(WEBHOOK_URL, json=payload)
|
63 |
-
response.raise_for_status()
|
64 |
-
logger.info(f"Successfully sent data to webhook. Status code: {response.status_code}")
|
65 |
-
except requests.exceptions.RequestException as e:
|
66 |
-
logger.error(f"Failed to send data to webhook: {e}")
|
67 |
-
|
68 |
-
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
69 |
-
logger.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
70 |
-
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
71 |
-
f"num_inference_steps: {num_inference_steps}")
|
72 |
-
|
73 |
-
try:
|
74 |
-
# 이미지 생성 요청
|
75 |
-
result = api_client.predict(
|
76 |
-
prompt=message,
|
77 |
-
seed=seed,
|
78 |
-
randomize_seed=randomize_seed,
|
79 |
-
width=width,
|
80 |
-
height=height,
|
81 |
-
guidance_scale=guidance_scale,
|
82 |
-
num_inference_steps=num_inference_steps,
|
83 |
-
api_name="/infer_t2i"
|
84 |
-
)
|
85 |
-
logger.info("API response received: %s", result)
|
86 |
-
|
87 |
-
# 결과 확인 및 처리
|
88 |
-
if isinstance(result, tuple) and len(result) >= 1:
|
89 |
-
local_image_path = result[0]
|
90 |
-
|
91 |
-
# 이미지 파일을 메모리에 로드
|
92 |
-
with open(local_image_path, "rb") as f:
|
93 |
-
image_data = f.read()
|
94 |
-
|
95 |
-
# Imgur에 이미지 업로드
|
96 |
-
imgur_url = upload_to_imgur(image_data)
|
97 |
-
|
98 |
-
if imgur_url:
|
99 |
-
# Webhook으로 데이터 전송
|
100 |
-
send_to_webhook(message, imgur_url)
|
101 |
-
return Image.open(io.BytesIO(image_data))
|
102 |
-
else:
|
103 |
-
raise ValueError("Failed to upload image to Imgur")
|
104 |
-
else:
|
105 |
-
raise ValueError("Unexpected API response format")
|
106 |
-
except Exception as e:
|
107 |
-
logger.error("Error during API request: %s", str(e))
|
108 |
-
return "Failed to generate image due to an error."
|
109 |
-
|
110 |
# ... (나머지 코드는 그대로 유지)
|
111 |
|
112 |
|
|
|
6 |
from PIL import Image
|
7 |
import io
|
8 |
import base64
|
9 |
+
import traceback
|
10 |
|
11 |
# 로깅 설정
|
12 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
19 |
WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY0MDYzMTA0MzE1MjZlNTUzYzUxM2Ei_pc"
|
20 |
|
21 |
# Imgur 클라이언트 ID
|
22 |
+
IMGUR_CLIENT_ID = "4990123196cbfcc"
|
23 |
|
24 |
def upload_to_imgur(image_data):
|
25 |
try:
|
|
|
49 |
|
50 |
return response.json()['data']['link']
|
51 |
except Exception as e:
|
52 |
+
logger.error(f"Failed to upload image to Imgur: {str(e)}")
|
53 |
+
logger.error(f"Traceback: {traceback.format_exc()}")
|
54 |
if hasattr(e, 'response'):
|
55 |
logger.error(f"Response content: {e.response.text}")
|
56 |
return None
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# ... (나머지 코드는 그대로 유지)
|
59 |
|
60 |
|