Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,10 @@ import requests
|
|
7 |
from datetime import datetime
|
8 |
from PIL import Image
|
9 |
import io
|
|
|
10 |
|
11 |
# 로깅 설정
|
12 |
-
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
notion_logger = logging.getLogger('notion')
|
14 |
notion_logger.setLevel(logging.DEBUG)
|
15 |
|
@@ -19,9 +20,13 @@ api_client = Client("http://211.233.58.202:7960/")
|
|
19 |
# Notion 클라이언트 설정
|
20 |
NOTION_TOKEN = os.getenv("NOTION_TOKEN")
|
21 |
NOTION_DATABASE_ID = "88c9bdadcb2044129af77d5932e1a82a"
|
22 |
-
notion = NotionClient(auth=NOTION_TOKEN)
|
23 |
|
24 |
def test_notion_connection():
|
|
|
|
|
|
|
|
|
|
|
25 |
try:
|
26 |
notion_logger.debug("Testing Notion connection...")
|
27 |
user_info = notion.users.me()
|
@@ -38,7 +43,20 @@ def test_notion_connection():
|
|
38 |
notion_logger.error(f"Notion API response: {e.response.text}")
|
39 |
return False
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def add_to_notion(prompt, image_path):
|
|
|
|
|
|
|
|
|
42 |
try:
|
43 |
notion_logger.debug(f"Adding to Notion - Prompt: {prompt}, Image Path: {image_path}")
|
44 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
@@ -56,7 +74,6 @@ def add_to_notion(prompt, image_path):
|
|
56 |
notion_logger.error(f"Error adding to Notion: {str(e)}")
|
57 |
if hasattr(e, 'response'):
|
58 |
notion_logger.error(f"Notion API response: {e.response.text}")
|
59 |
-
raise
|
60 |
|
61 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
62 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
@@ -90,6 +107,7 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
90 |
return "Failed to generate image due to an error."
|
91 |
|
92 |
|
|
|
93 |
css = """
|
94 |
footer {
|
95 |
visibility: hidden;
|
@@ -160,12 +178,10 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
160 |
|
161 |
|
162 |
|
|
|
|
|
163 |
if __name__ == "__main__":
|
164 |
notion_logger.info(f"Starting application with Notion Database ID: {NOTION_DATABASE_ID}")
|
165 |
notion_logger.info(f"Notion Token (first 5 chars): {NOTION_TOKEN[:5] if NOTION_TOKEN else 'Not set'}")
|
166 |
|
167 |
-
|
168 |
-
notion_logger.info("Notion connection test passed. Starting Gradio interface...")
|
169 |
-
demo.launch()
|
170 |
-
else:
|
171 |
-
notion_logger.error("Failed to connect to Notion. Please check your token and database ID.")
|
|
|
7 |
from datetime import datetime
|
8 |
from PIL import Image
|
9 |
import io
|
10 |
+
import sys
|
11 |
|
12 |
# 로깅 설정
|
13 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', stream=sys.stdout)
|
14 |
notion_logger = logging.getLogger('notion')
|
15 |
notion_logger.setLevel(logging.DEBUG)
|
16 |
|
|
|
20 |
# Notion 클라이언트 설정
|
21 |
NOTION_TOKEN = os.getenv("NOTION_TOKEN")
|
22 |
NOTION_DATABASE_ID = "88c9bdadcb2044129af77d5932e1a82a"
|
|
|
23 |
|
24 |
def test_notion_connection():
|
25 |
+
if not NOTION_TOKEN:
|
26 |
+
notion_logger.error("NOTION_TOKEN is not set. Please set the environment variable.")
|
27 |
+
return False
|
28 |
+
|
29 |
+
notion = NotionClient(auth=NOTION_TOKEN)
|
30 |
try:
|
31 |
notion_logger.debug("Testing Notion connection...")
|
32 |
user_info = notion.users.me()
|
|
|
43 |
notion_logger.error(f"Notion API response: {e.response.text}")
|
44 |
return False
|
45 |
|
46 |
+
# Notion 연결 테스트 실행
|
47 |
+
notion_connection_successful = test_notion_connection()
|
48 |
+
|
49 |
+
if notion_connection_successful:
|
50 |
+
notion = NotionClient(auth=NOTION_TOKEN)
|
51 |
+
else:
|
52 |
+
notion_logger.error("Failed to connect to Notion. The application will continue without Notion integration.")
|
53 |
+
notion = None
|
54 |
+
|
55 |
def add_to_notion(prompt, image_path):
|
56 |
+
if not notion:
|
57 |
+
notion_logger.warning("Notion integration is not available. Skipping add_to_notion.")
|
58 |
+
return
|
59 |
+
|
60 |
try:
|
61 |
notion_logger.debug(f"Adding to Notion - Prompt: {prompt}, Image Path: {image_path}")
|
62 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
74 |
notion_logger.error(f"Error adding to Notion: {str(e)}")
|
75 |
if hasattr(e, 'response'):
|
76 |
notion_logger.error(f"Notion API response: {e.response.text}")
|
|
|
77 |
|
78 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
79 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
|
|
107 |
return "Failed to generate image due to an error."
|
108 |
|
109 |
|
110 |
+
|
111 |
css = """
|
112 |
footer {
|
113 |
visibility: hidden;
|
|
|
178 |
|
179 |
|
180 |
|
181 |
+
# ... (나머지 코드는 그대로 유지)
|
182 |
+
|
183 |
if __name__ == "__main__":
|
184 |
notion_logger.info(f"Starting application with Notion Database ID: {NOTION_DATABASE_ID}")
|
185 |
notion_logger.info(f"Notion Token (first 5 chars): {NOTION_TOKEN[:5] if NOTION_TOKEN else 'Not set'}")
|
186 |
|
187 |
+
demo.launch()
|
|
|
|
|
|
|
|