Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,37 +9,54 @@ from PIL import Image
|
|
| 9 |
import io
|
| 10 |
|
| 11 |
# 로깅 설정
|
| 12 |
-
logging.basicConfig(level=logging.
|
| 13 |
|
| 14 |
# API 클라이언트 설정
|
| 15 |
api_client = Client("http://211.233.58.202:7960/")
|
| 16 |
|
| 17 |
# Notion 클라이언트 설정
|
| 18 |
NOTION_TOKEN = os.getenv("NOTION_TOKEN")
|
| 19 |
-
NOTION_DATABASE_ID = "
|
| 20 |
notion = NotionClient(auth=NOTION_TOKEN)
|
| 21 |
|
| 22 |
def add_to_notion(prompt, image_path):
|
| 23 |
try:
|
|
|
|
| 24 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 25 |
|
| 26 |
new_page = {
|
| 27 |
"Prompt": {"title": [{"text": {"content": prompt}}]},
|
| 28 |
-
"Image": {"url": image_path},
|
| 29 |
"Date": {"date": {"start": now}}
|
| 30 |
}
|
|
|
|
|
|
|
| 31 |
response = notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
|
| 32 |
logging.info(f"Successfully added to Notion: {response}")
|
| 33 |
except Exception as e:
|
| 34 |
logging.error(f"Error adding to Notion: {str(e)}")
|
| 35 |
logging.error(f"Database ID: {NOTION_DATABASE_ID}")
|
| 36 |
-
logging.error(f"
|
| 37 |
-
logging.error(f"Image path: {image_path}")
|
| 38 |
if hasattr(e, 'response'):
|
| 39 |
logging.error(f"Full Notion API response: {e.response.text}")
|
| 40 |
-
logging.error("Please make sure the Notion integration has access to the database and the database ID is correct.")
|
| 41 |
-
raise
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 45 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
|
@@ -72,14 +89,7 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
| 72 |
logging.error("Error during API request: %s", str(e))
|
| 73 |
return "Failed to generate image due to an error."
|
| 74 |
|
| 75 |
-
def use_prompt(prompt):
|
| 76 |
-
return prompt
|
| 77 |
|
| 78 |
-
css = """
|
| 79 |
-
footer {
|
| 80 |
-
visibility: hidden;
|
| 81 |
-
}
|
| 82 |
-
"""
|
| 83 |
|
| 84 |
css = """
|
| 85 |
footer {
|
|
@@ -148,5 +158,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
| 148 |
outputs=output_image
|
| 149 |
)
|
| 150 |
|
|
|
|
|
|
|
| 151 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 152 |
demo.launch()
|
|
|
|
| 9 |
import io
|
| 10 |
|
| 11 |
# 로깅 설정
|
| 12 |
+
logging.basicConfig(level=logging.DEBUG) # DEBUG 레벨로 변경
|
| 13 |
|
| 14 |
# API 클라이언트 설정
|
| 15 |
api_client = Client("http://211.233.58.202:7960/")
|
| 16 |
|
| 17 |
# Notion 클라이언트 설정
|
| 18 |
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 |
+
logging.debug(f"Adding to Notion - Prompt: {prompt}, Image Path: {image_path}")
|
| 25 |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 26 |
|
| 27 |
new_page = {
|
| 28 |
"Prompt": {"title": [{"text": {"content": prompt}}]},
|
| 29 |
+
"Image": {"url": f"http://211.233.58.202:7960/file={image_path}"},
|
| 30 |
"Date": {"date": {"start": now}}
|
| 31 |
}
|
| 32 |
+
logging.debug(f"New page properties: {new_page}")
|
| 33 |
+
|
| 34 |
response = notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
|
| 35 |
logging.info(f"Successfully added to Notion: {response}")
|
| 36 |
except Exception as e:
|
| 37 |
logging.error(f"Error adding to Notion: {str(e)}")
|
| 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 |
logging.error(f"Full Notion API response: {e.response.text}")
|
|
|
|
|
|
|
| 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):
|
| 62 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
|
|
|
| 89 |
logging.error("Error during API request: %s", str(e))
|
| 90 |
return "Failed to generate image due to an error."
|
| 91 |
|
|
|
|
|
|
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
css = """
|
| 95 |
footer {
|
|
|
|
| 158 |
outputs=output_image
|
| 159 |
)
|
| 160 |
|
| 161 |
+
|
| 162 |
+
|
| 163 |
if __name__ == "__main__":
|
| 164 |
+
logging.info(f"Starting application with Notion Database ID: {NOTION_DATABASE_ID}")
|
| 165 |
+
logging.info(f"Notion Token (first 5 chars): {NOTION_TOKEN[:5]}")
|
| 166 |
demo.launch()
|