Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,9 @@ import gradio as gr
|
|
2 |
from gradio_client import Client
|
3 |
import os
|
4 |
import logging
|
5 |
-
|
|
|
|
|
6 |
|
7 |
# 로깅 설정
|
8 |
logging.basicConfig(level=logging.INFO)
|
@@ -10,6 +12,20 @@ logging.basicConfig(level=logging.INFO)
|
|
10 |
# API 클라이언트 설정
|
11 |
api_client = Client("http://211.233.58.202:7960/")
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
14 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
15 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
@@ -31,7 +47,10 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
31 |
|
32 |
# 결과 확인 및 처리
|
33 |
if isinstance(result, dict) and 'url' in result:
|
34 |
-
|
|
|
|
|
|
|
35 |
elif isinstance(result, tuple):
|
36 |
logging.error("Unexpected tuple response: %s", result)
|
37 |
return result[0]
|
@@ -41,6 +60,8 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
41 |
logging.error("Error during API request: %s", str(e))
|
42 |
return "Failed to generate image due to an error."
|
43 |
|
|
|
|
|
44 |
css = """
|
45 |
footer {
|
46 |
visibility: hidden;
|
|
|
2 |
from gradio_client import Client
|
3 |
import os
|
4 |
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)
|
|
|
12 |
# API 클라이언트 설정
|
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)
|
28 |
+
|
29 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
30 |
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
31 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
|
|
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]
|
|
|
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 = """
|
66 |
footer {
|
67 |
visibility: hidden;
|