Update app.py
Browse files
app.py
CHANGED
@@ -2,86 +2,31 @@ import gradio as gr
|
|
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 |
-
from PIL import Image
|
9 |
-
import io
|
10 |
-
import sys
|
11 |
|
12 |
# ๋ก๊น
์ค์
|
13 |
-
logging.basicConfig(level=logging.
|
14 |
-
logger = logging.getLogger(__name__)
|
15 |
-
|
16 |
-
try:
|
17 |
-
import gradio as gr
|
18 |
-
from gradio_client import Client
|
19 |
-
import os
|
20 |
-
from notion_client import Client as NotionClient
|
21 |
-
import requests
|
22 |
-
from datetime import datetime
|
23 |
-
from PIL import Image
|
24 |
-
import io
|
25 |
-
logger.info("All modules imported successfully")
|
26 |
-
except ImportError as e:
|
27 |
-
logger.error(f"Error importing modules: {e}")
|
28 |
-
sys.exit(1)
|
29 |
|
30 |
# API ํด๋ผ์ด์ธํธ ์ค์
|
31 |
api_client = Client("http://211.233.58.202:7960/")
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
NOTION_DATABASE_ID = "88c9bdadcb2044129af77d5932e1a82a"
|
36 |
-
|
37 |
-
def test_notion_connection():
|
38 |
-
logger.info("Starting Notion connection test")
|
39 |
-
if not NOTION_TOKEN:
|
40 |
-
logger.error("NOTION_TOKEN is not set. Please set the environment variable.")
|
41 |
-
return False
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
try:
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
db_info = notion.databases.retrieve(database_id=NOTION_DATABASE_ID)
|
51 |
-
logger.info(f"Successfully retrieved database info: {db_info}")
|
52 |
-
|
53 |
-
return True
|
54 |
-
except Exception as e:
|
55 |
-
logger.error(f"Error connecting to Notion: {str(e)}")
|
56 |
-
if hasattr(e, 'response'):
|
57 |
-
logger.error(f"Notion API response: {e.response.text}")
|
58 |
-
return False
|
59 |
-
|
60 |
-
def add_to_notion(prompt, image_path):
|
61 |
-
if not notion:
|
62 |
-
logger.warning("Notion integration is not available. Skipping add_to_notion.")
|
63 |
-
return
|
64 |
-
|
65 |
-
try:
|
66 |
-
logger.debug(f"Adding to Notion - Prompt: {prompt}, Image Path: {image_path}")
|
67 |
-
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
68 |
-
|
69 |
-
new_page = {
|
70 |
-
"Prompt": {"title": [{"text": {"content": prompt}}]},
|
71 |
-
"Image": {"url": f"http://211.233.58.202:7960/file={image_path}"},
|
72 |
-
"Date": {"date": {"start": now}}
|
73 |
-
}
|
74 |
-
logger.debug(f"New page properties: {new_page}")
|
75 |
-
|
76 |
-
response = notion.pages.create(parent={"database_id": NOTION_DATABASE_ID}, properties=new_page)
|
77 |
-
logger.info(f"Successfully added to Notion: {response}")
|
78 |
-
except Exception as e:
|
79 |
-
logger.error(f"Error adding to Notion: {str(e)}")
|
80 |
-
if hasattr(e, 'response'):
|
81 |
-
logger.error(f"Notion API response: {e.response.text}")
|
82 |
|
83 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
84 |
-
|
85 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
86 |
f"num_inference_steps: {num_inference_steps}")
|
87 |
|
@@ -97,37 +42,43 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
|
|
97 |
num_inference_steps=num_inference_steps,
|
98 |
api_name="/infer_t2i"
|
99 |
)
|
100 |
-
|
101 |
|
102 |
# ๊ฒฐ๊ณผ ํ์ธ ๋ฐ ์ฒ๋ฆฌ
|
103 |
-
if isinstance(result,
|
104 |
-
|
105 |
-
#
|
106 |
-
|
107 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
else:
|
109 |
raise ValueError("Unexpected API response format")
|
110 |
except Exception as e:
|
111 |
-
|
112 |
return "Failed to generate image due to an error."
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
css = """
|
118 |
footer {
|
119 |
visibility: hidden;
|
120 |
}
|
121 |
"""
|
122 |
|
|
|
|
|
|
|
123 |
examples = [
|
124 |
-
["A glamorous young woman with long, wavy blonde hair and smokey eye makeup, posing in a luxury hotel room. She
|
125 |
["A fit male fitness influencer with short dark hair and stubble, standing shirtless in a modern gym. He has defined abs and arm muscles, and is holding a protein shake in one hand and a card that says 'openfree.ai' in the other. Bright, clean lighting highlights his physique.", "q2.webp"],
|
126 |
-
["A bohemian-style female travel blogger with sun-kissed skin and messy beach waves, sitting on a tropical beach at sunset. She
|
127 |
-
["A trendy male fashion influencer with perfectly styled hair and designer stubble, posing on a city street. He
|
128 |
-
["A fresh-faced young female beauty guru with freckles and natural makeup, sitting at a vanity covered in cosmetics. She
|
129 |
-
["A stylish young woman with long, wavy ombre hair and winged eyeliner, posing in front of a neon-lit city skyline at night. She
|
130 |
-
[
|
131 |
["Photo realistic scene inspired by LOTR: [A tiny red dragon sleeps curled up in a nest on a medieval wizard's table]. Shot with a macro lens (f/2.8, 50mm) and a Canon EOSR5, the soft focus captures [the cozy morning light filtering through a near by window]. The pastel colors and whimsical steam shapes enhance the serene atmosphere, evoking a DnD RPG setting. The image is rendered in 16K and 8K, highlighting [the intricate details and medieval charm].", "q8.webp"],
|
132 |
["์ฌ๊ธ๋ผ์ค๋ฅผ ์ฐฉ์ฉํ ๊ท์ฌ์ด ๊ฐ์์ง๊ฐ 'Openfree.ai'๋ผ๊ณ ์ฐ์ฌ์ง ํ์งํ์ ๋ค๊ณ ์๋ค.", "q9.webp"],
|
133 |
["๋ฏธ๋ ์ ์ธ ๋์์ ํด์ง๋ ํ๊ฒฝ", "q10.webp"],
|
@@ -143,7 +94,12 @@ examples = [
|
|
143 |
["A fantasy map of a fictional world, with detailed terrain and cities.", "q19.webp"]
|
144 |
]
|
145 |
|
|
|
|
|
|
|
146 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
|
|
|
147 |
with gr.Row():
|
148 |
input_text = gr.Textbox(label="Enter your prompt for image generation")
|
149 |
output_image = gr.Image(label="Generated Image")
|
@@ -181,22 +137,5 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
181 |
outputs=output_image
|
182 |
)
|
183 |
|
184 |
-
|
185 |
-
|
186 |
-
# ... (๋๋จธ์ง ์ฝ๋๋ ๊ทธ๋๋ก ์ ์ง)
|
187 |
-
|
188 |
if __name__ == "__main__":
|
189 |
-
logger.info("Starting application")
|
190 |
-
logger.info(f"Notion Database ID: {NOTION_DATABASE_ID}")
|
191 |
-
logger.info(f"Notion Token (first 5 chars): {NOTION_TOKEN[:5] if NOTION_TOKEN else 'Not set'}")
|
192 |
-
|
193 |
-
notion_connection_successful = test_notion_connection()
|
194 |
-
|
195 |
-
if notion_connection_successful:
|
196 |
-
logger.info("Notion connection test passed. Starting Gradio interface...")
|
197 |
-
notion = NotionClient(auth=NOTION_TOKEN)
|
198 |
-
else:
|
199 |
-
logger.error("Failed to connect to Notion. The application will continue without Notion integration.")
|
200 |
-
notion = None
|
201 |
-
|
202 |
demo.launch()
|
|
|
2 |
from gradio_client import Client
|
3 |
import os
|
4 |
import logging
|
|
|
5 |
import requests
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# ๋ก๊น
์ค์
|
8 |
+
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# API ํด๋ผ์ด์ธํธ ์ค์
|
11 |
api_client = Client("http://211.233.58.202:7960/")
|
12 |
|
13 |
+
# Webhook URL
|
14 |
+
WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY0MDYzMTA0MzE1MjZlNTUzYzUxM2Ei_pc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
def send_to_webhook(prompt, image_url):
|
17 |
+
payload = {
|
18 |
+
"prompt": prompt,
|
19 |
+
"image_url": image_url
|
20 |
+
}
|
21 |
try:
|
22 |
+
response = requests.post(WEBHOOK_URL, json=payload)
|
23 |
+
response.raise_for_status()
|
24 |
+
logging.info(f"Successfully sent data to webhook. Status code: {response.status_code}")
|
25 |
+
except requests.exceptions.RequestException as e:
|
26 |
+
logging.error(f"Failed to send data to webhook: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
29 |
+
logging.info(f"Received message: {message}, seed: {seed}, randomize_seed: {randomize_seed}, "
|
30 |
f"width: {width}, height: {height}, guidance_scale: {guidance_scale}, "
|
31 |
f"num_inference_steps: {num_inference_steps}")
|
32 |
|
|
|
42 |
num_inference_steps=num_inference_steps,
|
43 |
api_name="/infer_t2i"
|
44 |
)
|
45 |
+
logging.info("API response received: %s", result)
|
46 |
|
47 |
# ๊ฒฐ๊ณผ ํ์ธ ๋ฐ ์ฒ๋ฆฌ
|
48 |
+
if isinstance(result, dict) and 'url' in result:
|
49 |
+
image_url = result['url']
|
50 |
+
# Webhook์ผ๋ก ๋ฐ์ดํฐ ์ ์ก
|
51 |
+
send_to_webhook(message, image_url)
|
52 |
+
return image_url
|
53 |
+
elif isinstance(result, tuple):
|
54 |
+
logging.error("Unexpected tuple response: %s", result)
|
55 |
+
image_url = result[0]
|
56 |
+
# Webhook์ผ๋ก ๋ฐ์ดํฐ ์ ์ก
|
57 |
+
send_to_webhook(message, image_url)
|
58 |
+
return image_url
|
59 |
else:
|
60 |
raise ValueError("Unexpected API response format")
|
61 |
except Exception as e:
|
62 |
+
logging.error("Error during API request: %s", str(e))
|
63 |
return "Failed to generate image due to an error."
|
64 |
|
|
|
|
|
|
|
65 |
css = """
|
66 |
footer {
|
67 |
visibility: hidden;
|
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"],
|
76 |
["A fit male fitness influencer with short dark hair and stubble, standing shirtless in a modern gym. He has defined abs and arm muscles, and is holding a protein shake in one hand and a card that says 'openfree.ai' in the other. Bright, clean lighting highlights his physique.", "q2.webp"],
|
77 |
+
["A bohemian-style female travel blogger with sun-kissed skin and messy beach waves, sitting on a tropical beach at sunset. Sheโs wearing a flowy white sundress and holding up a weathered postcard with 'openfree.ai' scrawled on it. Golden hour lighting bathes the scene in warm tones. ", "q3.webp"],
|
78 |
+
["A trendy male fashion influencer with perfectly styled hair and designer stubble, posing on a city street. Heโs wearing a tailored suit and holding up a sleek black business card with 'openfree.ai' printed in minimalist white font. The background shows blurred city lights, creating a chic urban atmosphere.", "q4.webp"],
|
79 |
+
["A fresh-faced young female beauty guru with freckles and natural makeup, sitting at a vanity covered in cosmetics. Sheโs wearing a pastel pink robe and holding up a makeup palette with 'openfree.ai' written on it in lipstick. Soft, flattering lighting enhances her radiant complexion. ", "q5.webp"],
|
80 |
+
["A stylish young woman with long, wavy ombre hair and winged eyeliner, posing in front of a neon-lit city skyline at night. Sheโs wearing a sleek black leather jacket over a sparkly crop top and holding up a holographic business card that says 'openfree.ai' in futuristic font. The card reflects the colorful neon lights, creating a cyberpunk aesthetic.", "q6.webp"],
|
81 |
+
["Create a surreal advertisement poster for a fictional time travel agency. The background should depict a swirling vortex of clock faces and historical landmarks from different eras. In the foreground, place large, bold text that reads โAI TOURS: YOUR PAST IS OUR FUTUREโ in a retro-futuristic font. The text should appear to be partially disintegrating into particles that are being sucked into the time vortex. Include smaller text at the bottom with fictional pricing and the slogan โHistory is just a ticket away!โ", "q7.webp"],
|
82 |
["Photo realistic scene inspired by LOTR: [A tiny red dragon sleeps curled up in a nest on a medieval wizard's table]. Shot with a macro lens (f/2.8, 50mm) and a Canon EOSR5, the soft focus captures [the cozy morning light filtering through a near by window]. The pastel colors and whimsical steam shapes enhance the serene atmosphere, evoking a DnD RPG setting. The image is rendered in 16K and 8K, highlighting [the intricate details and medieval charm].", "q8.webp"],
|
83 |
["์ฌ๊ธ๋ผ์ค๋ฅผ ์ฐฉ์ฉํ ๊ท์ฌ์ด ๊ฐ์์ง๊ฐ 'Openfree.ai'๋ผ๊ณ ์ฐ์ฌ์ง ํ์งํ์ ๋ค๊ณ ์๋ค.", "q9.webp"],
|
84 |
["๋ฏธ๋ ์ ์ธ ๋์์ ํด์ง๋ ํ๊ฒฝ", "q10.webp"],
|
|
|
94 |
["A fantasy map of a fictional world, with detailed terrain and cities.", "q19.webp"]
|
95 |
]
|
96 |
|
97 |
+
def use_prompt(prompt):
|
98 |
+
return prompt
|
99 |
+
|
100 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
101 |
+
|
102 |
+
|
103 |
with gr.Row():
|
104 |
input_text = gr.Textbox(label="Enter your prompt for image generation")
|
105 |
output_image = gr.Image(label="Generated Image")
|
|
|
137 |
outputs=output_image
|
138 |
)
|
139 |
|
|
|
|
|
|
|
|
|
140 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
demo.launch()
|