Update app.py
Browse files
app.py
CHANGED
@@ -3,30 +3,27 @@ from gradio_client import Client
|
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
import warnings
|
6 |
-
import torch
|
7 |
|
8 |
-
#
|
9 |
warnings.filterwarnings('ignore', category=UserWarning)
|
10 |
|
11 |
-
#
|
12 |
load_dotenv()
|
13 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
14 |
|
15 |
-
# Force CPU mode
|
16 |
-
os.environ['CUDA_VISIBLE_DEVICES'] = ''
|
17 |
-
if torch.cuda.is_available():
|
18 |
-
device = torch.device('cuda')
|
19 |
-
else:
|
20 |
-
device = torch.device('cpu')
|
21 |
-
|
22 |
def generate_diagram(prompt, width=1024, height=1024):
|
23 |
-
"""
|
24 |
try:
|
|
|
|
|
|
|
|
|
25 |
client = Client(
|
26 |
-
"black-forest-labs
|
27 |
hf_token=HF_TOKEN,
|
28 |
-
cpu_only=True # Force CPU mode
|
29 |
)
|
|
|
|
|
30 |
result = client.predict(
|
31 |
prompt,
|
32 |
1872187377, # seed
|
@@ -38,7 +35,7 @@ def generate_diagram(prompt, width=1024, height=1024):
|
|
38 |
)
|
39 |
return result
|
40 |
except Exception as e:
|
41 |
-
raise gr.Error(f"
|
42 |
|
43 |
# Convert example format for Gradio
|
44 |
GRADIO_EXAMPLES = [
|
@@ -284,52 +281,51 @@ GRADIO_EXAMPLES = [
|
|
284 |
for example in EXAMPLES
|
285 |
]
|
286 |
|
287 |
-
|
288 |
demo = gr.Interface(
|
289 |
fn=generate_diagram,
|
290 |
inputs=[
|
291 |
gr.Textbox(
|
292 |
-
label="
|
293 |
-
placeholder="
|
294 |
lines=10
|
295 |
),
|
296 |
gr.Slider(
|
297 |
-
label="
|
298 |
minimum=512,
|
299 |
maximum=2048,
|
300 |
step=128,
|
301 |
value=1024
|
302 |
),
|
303 |
gr.Slider(
|
304 |
-
label="
|
305 |
minimum=512,
|
306 |
maximum=2048,
|
307 |
step=128,
|
308 |
value=1024
|
309 |
)
|
310 |
],
|
311 |
-
outputs=gr.Image(label="
|
312 |
-
title="๐จ FLUX
|
313 |
-
description="
|
314 |
article="""
|
315 |
-
###
|
316 |
-
-
|
317 |
-
-
|
318 |
-
-
|
319 |
-
-
|
320 |
""",
|
321 |
examples=GRADIO_EXAMPLES,
|
322 |
cache_examples=True
|
323 |
)
|
324 |
|
|
|
325 |
if __name__ == "__main__":
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
except Exception as e:
|
335 |
-
print(f"Error launching app: {str(e)}")
|
|
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
import warnings
|
|
|
6 |
|
7 |
+
# ๊ฒฝ๊ณ ๋ฉ์์ง ์จ๊ธฐ๊ธฐ
|
8 |
warnings.filterwarnings('ignore', category=UserWarning)
|
9 |
|
10 |
+
# ํ๊ฒฝ ๋ณ์ ๋ก๋
|
11 |
load_dotenv()
|
12 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def generate_diagram(prompt, width=1024, height=1024):
|
15 |
+
"""FLUX AI๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ด์ด๊ทธ๋จ ์์ฑ"""
|
16 |
try:
|
17 |
+
# API ํธ์ถ์ ํตํด ์ด๋ฏธ์ง ์์ฑ
|
18 |
+
result = gr.Image.update(value=None) # ์ด๊ธฐ ์ํ๋ ๋น ์ด๋ฏธ์ง
|
19 |
+
|
20 |
+
# Hugging Face API ํธ์ถ
|
21 |
client = Client(
|
22 |
+
"https://black-forest-labs-flux-1-schnell.hf.space", # API ์๋ํฌ์ธํธ ์ง์ ์ง์
|
23 |
hf_token=HF_TOKEN,
|
|
|
24 |
)
|
25 |
+
|
26 |
+
# ์ด๋ฏธ์ง ์์ฑ
|
27 |
result = client.predict(
|
28 |
prompt,
|
29 |
1872187377, # seed
|
|
|
35 |
)
|
36 |
return result
|
37 |
except Exception as e:
|
38 |
+
raise gr.Error(f"๋ค์ด์ด๊ทธ๋จ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
39 |
|
40 |
# Convert example format for Gradio
|
41 |
GRADIO_EXAMPLES = [
|
|
|
281 |
for example in EXAMPLES
|
282 |
]
|
283 |
|
284 |
+
|
285 |
demo = gr.Interface(
|
286 |
fn=generate_diagram,
|
287 |
inputs=[
|
288 |
gr.Textbox(
|
289 |
+
label="๋ค์ด์ด๊ทธ๋จ ํ๋กฌํํธ",
|
290 |
+
placeholder="๋ค์ด์ด๊ทธ๋จ ๊ตฌ์กฐ๋ฅผ ์
๋ ฅํ์ธ์...",
|
291 |
lines=10
|
292 |
),
|
293 |
gr.Slider(
|
294 |
+
label="๋๋น",
|
295 |
minimum=512,
|
296 |
maximum=2048,
|
297 |
step=128,
|
298 |
value=1024
|
299 |
),
|
300 |
gr.Slider(
|
301 |
+
label="๋์ด",
|
302 |
minimum=512,
|
303 |
maximum=2048,
|
304 |
step=128,
|
305 |
value=1024
|
306 |
)
|
307 |
],
|
308 |
+
outputs=gr.Image(label="์์ฑ๋ ๋ค์ด์ด๊ทธ๋จ"),
|
309 |
+
title="๐จ FLUX ๋ค์ด์ด๊ทธ๋จ ์์ฑ๊ธฐ",
|
310 |
+
description="FLUX AI๋ฅผ ์ฌ์ฉํ์ฌ ์๋ฆ๋ค์ด ์๊ทธ๋ฆผ ์คํ์ผ์ ๋ค์ด์ด๊ทธ๋จ์ ์์ฑํฉ๋๋ค",
|
311 |
article="""
|
312 |
+
### ๋ ๋์ ๊ฒฐ๊ณผ๋ฅผ ์ํ ํ
|
313 |
+
- ๋ช
ํํ ๊ณ์ธต ๊ตฌ์กฐ ์ฌ์ฉ
|
314 |
+
- ๋๊ดํธ ์์ ์์ด์ฝ ์ค๋ช
ํฌํจ
|
315 |
+
- ๊ฐ๊ฒฐํ๊ณ ์๋ฏธ ์๋ ํ
์คํธ ์ฌ์ฉ
|
316 |
+
- ์ผ๊ด๋ ํ์ ์ ์ง
|
317 |
""",
|
318 |
examples=GRADIO_EXAMPLES,
|
319 |
cache_examples=True
|
320 |
)
|
321 |
|
322 |
+
# ์ฑ ์คํ
|
323 |
if __name__ == "__main__":
|
324 |
+
demo.launch(
|
325 |
+
server_name="0.0.0.0",
|
326 |
+
server_port=7860,
|
327 |
+
share=False,
|
328 |
+
show_error=True,
|
329 |
+
debug=True,
|
330 |
+
enable_queue=True # ํ ํ์ฑํ๋ก ์์ฒญ ๊ด๋ฆฌ
|
331 |
+
)
|
|
|
|