Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,8 @@ import io
|
|
8 |
import base64
|
9 |
|
10 |
# 로깅 설정
|
11 |
-
logging.basicConfig(level=logging.DEBUG)
|
|
|
12 |
|
13 |
# API 클라이언트 설정
|
14 |
api_client = Client("http://211.233.58.202:7960/")
|
@@ -21,23 +22,27 @@ IMGUR_CLIENT_ID = "여기에_당신의_IMGUR_CLIENT_ID를_입력하세요"
|
|
21 |
|
22 |
def upload_to_imgur(image_data):
|
23 |
try:
|
|
|
|
|
|
|
24 |
im_b64 = base64.b64encode(image_data).decode("utf-8")
|
25 |
|
26 |
url = "https://api.imgur.com/3/image"
|
27 |
-
payload = {'image': im_b64}
|
28 |
headers = {'Authorization': f'Client-ID {IMGUR_CLIENT_ID}'}
|
29 |
|
|
|
30 |
response = requests.post(url, headers=headers, data=payload)
|
31 |
-
|
32 |
-
|
33 |
|
34 |
response.raise_for_status()
|
35 |
|
36 |
return response.json()['data']['link']
|
37 |
-
except
|
38 |
-
|
39 |
if hasattr(e, 'response'):
|
40 |
-
|
41 |
return None
|
42 |
|
43 |
def send_to_webhook(prompt, image_url):
|
@@ -48,12 +53,12 @@ def send_to_webhook(prompt, image_url):
|
|
48 |
try:
|
49 |
response = requests.post(WEBHOOK_URL, json=payload)
|
50 |
response.raise_for_status()
|
51 |
-
|
52 |
except requests.exceptions.RequestException as e:
|
53 |
-
|
54 |
|
55 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
56 |
-
|
57 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
58 |
f"num_inference_steps: {num_inference_steps}")
|
59 |
|
@@ -69,7 +74,7 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
69 |
num_inference_steps=num_inference_steps,
|
70 |
api_name="/infer_t2i"
|
71 |
)
|
72 |
-
|
73 |
|
74 |
# 결과 확인 및 처리
|
75 |
if isinstance(result, tuple) and len(result) >= 1:
|
@@ -91,9 +96,12 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
91 |
else:
|
92 |
raise ValueError("Unexpected API response format")
|
93 |
except Exception as e:
|
94 |
-
|
95 |
return "Failed to generate image due to an error."
|
96 |
|
|
|
|
|
|
|
97 |
|
98 |
css = """
|
99 |
footer {
|
@@ -170,6 +178,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
170 |
outputs=output_image
|
171 |
)
|
172 |
|
|
|
173 |
if __name__ == "__main__":
|
174 |
-
|
175 |
demo.launch()
|
|
|
8 |
import base64
|
9 |
|
10 |
# 로깅 설정
|
11 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
|
14 |
# API 클라이언트 설정
|
15 |
api_client = Client("http://211.233.58.202:7960/")
|
|
|
22 |
|
23 |
def upload_to_imgur(image_data):
|
24 |
try:
|
25 |
+
logger.debug(f"Image data type: {type(image_data)}")
|
26 |
+
logger.debug(f"Image data length: {len(image_data)}")
|
27 |
+
|
28 |
im_b64 = base64.b64encode(image_data).decode("utf-8")
|
29 |
|
30 |
url = "https://api.imgur.com/3/image"
|
31 |
+
payload = {'image': im_b64, 'type': 'base64'}
|
32 |
headers = {'Authorization': f'Client-ID {IMGUR_CLIENT_ID}'}
|
33 |
|
34 |
+
logger.debug("Sending request to Imgur API")
|
35 |
response = requests.post(url, headers=headers, data=payload)
|
36 |
+
logger.debug(f"Imgur API response status: {response.status_code}")
|
37 |
+
logger.debug(f"Imgur API response content: {response.text}")
|
38 |
|
39 |
response.raise_for_status()
|
40 |
|
41 |
return response.json()['data']['link']
|
42 |
+
except Exception as e:
|
43 |
+
logger.error(f"Failed to upload image to Imgur: {e}")
|
44 |
if hasattr(e, 'response'):
|
45 |
+
logger.error(f"Response content: {e.response.text}")
|
46 |
return None
|
47 |
|
48 |
def send_to_webhook(prompt, image_url):
|
|
|
53 |
try:
|
54 |
response = requests.post(WEBHOOK_URL, json=payload)
|
55 |
response.raise_for_status()
|
56 |
+
logger.info(f"Successfully sent data to webhook. Status code: {response.status_code}")
|
57 |
except requests.exceptions.RequestException as e:
|
58 |
+
logger.error(f"Failed to send data to webhook: {e}")
|
59 |
|
60 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
61 |
+
logger.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
62 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
63 |
f"num_inference_steps: {num_inference_steps}")
|
64 |
|
|
|
74 |
num_inference_steps=num_inference_steps,
|
75 |
api_name="/infer_t2i"
|
76 |
)
|
77 |
+
logger.info("API response received: %s", result)
|
78 |
|
79 |
# 결과 확인 및 처리
|
80 |
if isinstance(result, tuple) and len(result) >= 1:
|
|
|
96 |
else:
|
97 |
raise ValueError("Unexpected API response format")
|
98 |
except Exception as e:
|
99 |
+
logger.error("Error during API request: %s", str(e))
|
100 |
return "Failed to generate image due to an error."
|
101 |
|
102 |
+
# ... (나머지 코드는 그대로 유지)
|
103 |
+
|
104 |
+
|
105 |
|
106 |
css = """
|
107 |
footer {
|
|
|
178 |
outputs=output_image
|
179 |
)
|
180 |
|
181 |
+
|
182 |
if __name__ == "__main__":
|
183 |
+
logger.info(f"Starting application with Imgur Client ID: {IMGUR_CLIENT_ID[:5]}...")
|
184 |
demo.launch()
|