Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ import requests
|
|
6 |
import pyimgur
|
7 |
from PIL import Image
|
8 |
import io
|
|
|
|
|
9 |
|
10 |
# 로깅 설정
|
11 |
logging.basicConfig(level=logging.INFO)
|
@@ -21,10 +23,10 @@ IMGUR_CLIENT_ID = "여기에_당신의_IMGUR_CLIENT_ID를_입력하세요"
|
|
21 |
imgur_client = pyimgur.Imgur(IMGUR_CLIENT_ID)
|
22 |
|
23 |
def convert_to_png(image_path):
|
24 |
-
with
|
25 |
-
|
26 |
-
|
27 |
-
return
|
28 |
|
29 |
def upload_to_imgur(image_path):
|
30 |
try:
|
@@ -70,8 +72,15 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
70 |
# 결과 확인 및 처리
|
71 |
if isinstance(result, tuple) and len(result) >= 1:
|
72 |
local_image_path = result[0]
|
|
|
|
|
|
|
|
|
|
|
73 |
# Imgur에 이미지 업로드
|
74 |
-
imgur_url = upload_to_imgur(
|
|
|
|
|
75 |
if imgur_url:
|
76 |
# Webhook으로 데이터 전송
|
77 |
send_to_webhook(message, imgur_url)
|
@@ -85,7 +94,6 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
85 |
return "Failed to generate image due to an error."
|
86 |
|
87 |
|
88 |
-
|
89 |
css = """
|
90 |
footer {
|
91 |
visibility: hidden;
|
|
|
6 |
import pyimgur
|
7 |
from PIL import Image
|
8 |
import io
|
9 |
+
import tempfile
|
10 |
+
import shutil
|
11 |
|
12 |
# 로깅 설정
|
13 |
logging.basicConfig(level=logging.INFO)
|
|
|
23 |
imgur_client = pyimgur.Imgur(IMGUR_CLIENT_ID)
|
24 |
|
25 |
def convert_to_png(image_path):
|
26 |
+
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp_file:
|
27 |
+
with Image.open(image_path) as img:
|
28 |
+
img.save(temp_file.name, 'PNG')
|
29 |
+
return temp_file.name
|
30 |
|
31 |
def upload_to_imgur(image_path):
|
32 |
try:
|
|
|
72 |
# 결과 확인 및 처리
|
73 |
if isinstance(result, tuple) and len(result) >= 1:
|
74 |
local_image_path = result[0]
|
75 |
+
# 임시 디렉토리에 이미지 복사
|
76 |
+
with tempfile.NamedTemporaryFile(suffix='.webp', delete=False) as temp_file:
|
77 |
+
shutil.copy2(local_image_path, temp_file.name)
|
78 |
+
temp_image_path = temp_file.name
|
79 |
+
|
80 |
# Imgur에 이미지 업로드
|
81 |
+
imgur_url = upload_to_imgur(temp_image_path)
|
82 |
+
os.remove(temp_image_path) # 임시 파일 삭제
|
83 |
+
|
84 |
if imgur_url:
|
85 |
# Webhook으로 데이터 전송
|
86 |
send_to_webhook(message, imgur_url)
|
|
|
94 |
return "Failed to generate image due to an error."
|
95 |
|
96 |
|
|
|
97 |
css = """
|
98 |
footer {
|
99 |
visibility: hidden;
|