fantaxy commited on
Commit
887c8af
1 Parent(s): 1f5b975

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -5,6 +5,8 @@ import logging
5
  from notion_client import Client as NotionClient
6
  import requests
7
  from datetime import datetime
 
 
8
 
9
  # 로깅 설정
10
  logging.basicConfig(level=logging.INFO)
@@ -13,15 +15,20 @@ logging.basicConfig(level=logging.INFO)
13
  api_client = Client("http://211.233.58.202:7960/")
14
 
15
  # Notion 클라이언트 설정
16
- NOTION_TOKEN = "secret_MpVfJphbfo4599fdczYfMYKNOpyzCcvkhhzk3lgTfVk"
17
  NOTION_DATABASE_ID = "b4ba17da43cd4bedb5482ef10e5ffc8d"
18
  notion = NotionClient(auth=NOTION_TOKEN)
19
 
20
- def add_to_notion(prompt, image_url):
21
  now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
 
 
 
 
 
22
  new_page = {
23
  "Prompt": {"title": [{"text": {"content": prompt}}]},
24
- "Image": {"files": [{"name": f"Generated Image {now}", "type": "external", "external": {"url": image_url}}]},
25
  "Date": {"date": {"start": now}}
26
  }
27
  notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
@@ -46,20 +53,19 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
46
  logging.info("API response received: %s", result)
47
 
48
  # 결과 확인 및 처리
49
- if isinstance(result, dict) and 'url' in result:
50
- image_url = result['url']
51
  # Notion에 추가
52
- add_to_notion(message, image_url)
53
- return image_url
54
- elif isinstance(result, tuple):
55
- logging.error("Unexpected tuple response: %s", result)
56
- return result[0]
57
  else:
58
  raise ValueError("Unexpected API response format")
59
  except Exception as e:
60
  logging.error("Error during API request: %s", str(e))
61
  return "Failed to generate image due to an error."
62
 
 
 
63
 
64
 
65
  css = """
@@ -68,8 +74,6 @@ footer {
68
  }
69
  """
70
 
71
-
72
-
73
  # 이미지 생성을 위한 예제 프롬프트
74
  examples = [
75
  ["A glamorous young woman with long, wavy blonde hair and smokey eye makeup, posing in a luxury hotel room. She’s wearing a sparkly gold cocktail dress and holding up a white card with 'openfree.ai' written on it in elegant calligraphy. Soft, warm lighting creates a luxurious atmosphere. ", "q1.webp"],
 
5
  from notion_client import Client as NotionClient
6
  import requests
7
  from datetime import datetime
8
+ from PIL import Image
9
+ import io
10
 
11
  # 로깅 설정
12
  logging.basicConfig(level=logging.INFO)
 
15
  api_client = Client("http://211.233.58.202:7960/")
16
 
17
  # Notion 클라이언트 설정
18
+ NOTION_TOKEN = "your_notion_integration_token"
19
  NOTION_DATABASE_ID = "b4ba17da43cd4bedb5482ef10e5ffc8d"
20
  notion = NotionClient(auth=NOTION_TOKEN)
21
 
22
+ def add_to_notion(prompt, image_path):
23
  now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
24
+
25
+ # 이미지를 Notion에 업로드
26
+ with open(image_path, "rb") as f:
27
+ response = notion.files.upload(file=f)
28
+
29
  new_page = {
30
  "Prompt": {"title": [{"text": {"content": prompt}}]},
31
+ "Image": {"files": [{"name": f"Generated Image {now}", "type": "file", "file": {"url": response.url}}]},
32
  "Date": {"date": {"start": now}}
33
  }
34
  notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
 
53
  logging.info("API response received: %s", result)
54
 
55
  # 결과 확인 및 처리
56
+ if isinstance(result, tuple) and len(result) >= 1:
57
+ image_path = result[0]
58
  # Notion에 추가
59
+ add_to_notion(message, image_path)
60
+ return Image.open(image_path)
 
 
 
61
  else:
62
  raise ValueError("Unexpected API response format")
63
  except Exception as e:
64
  logging.error("Error during API request: %s", str(e))
65
  return "Failed to generate image due to an error."
66
 
67
+ def use_prompt(prompt):
68
+ return prompt
69
 
70
 
71
  css = """
 
74
  }
75
  """
76
 
 
 
77
  # 이미지 생성을 위한 예제 프롬프트
78
  examples = [
79
  ["A glamorous young woman with long, wavy blonde hair and smokey eye makeup, posing in a luxury hotel room. She’s wearing a sparkly gold cocktail dress and holding up a white card with 'openfree.ai' written on it in elegant calligraphy. Soft, warm lighting creates a luxurious atmosphere. ", "q1.webp"],