Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,9 @@ from PIL import Image
|
|
| 9 |
import io
|
| 10 |
|
| 11 |
# 로깅 설정
|
| 12 |
-
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# API 클라이언트 설정
|
| 15 |
api_client = Client("http://211.233.58.202:7960/")
|
|
@@ -19,9 +21,26 @@ NOTION_TOKEN = os.getenv("NOTION_TOKEN")
|
|
| 19 |
NOTION_DATABASE_ID = "88c9bdadcb2044129af77d5932e1a82a"
|
| 20 |
notion = NotionClient(auth=NOTION_TOKEN)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def add_to_notion(prompt, image_path):
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 26 |
|
| 27 |
new_page = {
|
|
@@ -29,33 +48,14 @@ def add_to_notion(prompt, image_path):
|
|
| 29 |
"Image": {"url": f"http://211.233.58.202:7960/file={image_path}"},
|
| 30 |
"Date": {"date": {"start": now}}
|
| 31 |
}
|
| 32 |
-
|
| 33 |
|
| 34 |
response = notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
|
| 35 |
-
|
| 36 |
except Exception as e:
|
| 37 |
-
|
| 38 |
-
logging.error(f"Database ID: {NOTION_DATABASE_ID}")
|
| 39 |
-
logging.error(f"Notion Token: {NOTION_TOKEN[:5]}...{NOTION_TOKEN[-5:]}") # 토큰의 일부만 로깅
|
| 40 |
if hasattr(e, 'response'):
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# 데이터베이스 정보 확인
|
| 44 |
-
try:
|
| 45 |
-
logging.debug("Attempting to retrieve database info...")
|
| 46 |
-
db_info = notion.databases.retrieve(database_id=NOTION_DATABASE_ID)
|
| 47 |
-
logging.info(f"Database info: {db_info}")
|
| 48 |
-
except Exception as db_error:
|
| 49 |
-
logging.error(f"Error retrieving database info: {str(db_error)}")
|
| 50 |
-
|
| 51 |
-
# 통합 정보 확인
|
| 52 |
-
try:
|
| 53 |
-
logging.debug("Attempting to retrieve user info...")
|
| 54 |
-
user_info = notion.users.me()
|
| 55 |
-
logging.info(f"User info: {user_info}")
|
| 56 |
-
except Exception as user_error:
|
| 57 |
-
logging.error(f"Error retrieving user info: {str(user_error)}")
|
| 58 |
-
|
| 59 |
raise
|
| 60 |
|
| 61 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
|
@@ -90,7 +90,6 @@ 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 |
-
|
| 94 |
css = """
|
| 95 |
footer {
|
| 96 |
visibility: hidden;
|
|
@@ -160,7 +159,13 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
| 160 |
|
| 161 |
|
| 162 |
|
|
|
|
| 163 |
if __name__ == "__main__":
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
| 16 |
# API 클라이언트 설정
|
| 17 |
api_client = Client("http://211.233.58.202:7960/")
|
|
|
|
| 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()
|
| 28 |
+
notion_logger.info(f"Successfully connected to Notion. User info: {user_info}")
|
| 29 |
+
|
| 30 |
+
notion_logger.debug("Retrieving database info...")
|
| 31 |
+
db_info = notion.databases.retrieve(database_id=NOTION_DATABASE_ID)
|
| 32 |
+
notion_logger.info(f"Successfully retrieved database info: {db_info}")
|
| 33 |
+
|
| 34 |
+
return True
|
| 35 |
+
except Exception as e:
|
| 36 |
+
notion_logger.error(f"Error connecting to Notion: {str(e)}")
|
| 37 |
+
if hasattr(e, 'response'):
|
| 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")
|
| 45 |
|
| 46 |
new_page = {
|
|
|
|
| 48 |
"Image": {"url": f"http://211.233.58.202:7960/file={image_path}"},
|
| 49 |
"Date": {"date": {"start": now}}
|
| 50 |
}
|
| 51 |
+
notion_logger.debug(f"New page properties: {new_page}")
|
| 52 |
|
| 53 |
response = notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
|
| 54 |
+
notion_logger.info(f"Successfully added to Notion: {response}")
|
| 55 |
except Exception as e:
|
| 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):
|
|
|
|
| 90 |
return "Failed to generate image due to an error."
|
| 91 |
|
| 92 |
|
|
|
|
| 93 |
css = """
|
| 94 |
footer {
|
| 95 |
visibility: hidden;
|
|
|
|
| 159 |
|
| 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 |
+
if test_notion_connection():
|
| 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.")
|