Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import random
|
2 |
import os
|
3 |
import uuid
|
@@ -12,20 +27,6 @@ import torch
|
|
12 |
from diffusers import DiffusionPipeline
|
13 |
from PIL import Image
|
14 |
|
15 |
-
# ===== Fix: Import spaces for Hugging Face Spaces =====
|
16 |
-
try:
|
17 |
-
import spaces
|
18 |
-
HF_SPACES = True
|
19 |
-
except ImportError:
|
20 |
-
# If running locally, create a dummy decorator
|
21 |
-
def spaces_gpu_decorator(duration=60):
|
22 |
-
def decorator(func):
|
23 |
-
return func
|
24 |
-
return decorator
|
25 |
-
spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})()
|
26 |
-
HF_SPACES = False
|
27 |
-
print("Warning: Running without Hugging Face Spaces GPU allocation")
|
28 |
-
|
29 |
# ===== OpenAI ์ค์ =====
|
30 |
from openai import OpenAI
|
31 |
|
@@ -79,7 +80,7 @@ def is_korean(text: str) -> bool:
|
|
79 |
# ===== ๋ฒ์ญ & ์ฆ๊ฐ ํจ์ =====
|
80 |
|
81 |
def openai_translate(text: str, retries: int = 3) -> str:
|
82 |
-
"""ํ๊ธ์ ์์ด๋ก ๋ฒ์ญ (OpenAI GPT-
|
83 |
if not is_korean(text):
|
84 |
return text
|
85 |
|
@@ -90,7 +91,7 @@ def openai_translate(text: str, retries: int = 3) -> str:
|
|
90 |
for attempt in range(retries):
|
91 |
try:
|
92 |
res = client.chat.completions.create(
|
93 |
-
model="gpt-4o-mini",
|
94 |
messages=[
|
95 |
{
|
96 |
"role": "system",
|
|
|
1 |
+
# ===== CRITICAL: Import spaces FIRST before any CUDA operations =====
|
2 |
+
try:
|
3 |
+
import spaces
|
4 |
+
HF_SPACES = True
|
5 |
+
except ImportError:
|
6 |
+
# If running locally, create a dummy decorator
|
7 |
+
def spaces_gpu_decorator(duration=60):
|
8 |
+
def decorator(func):
|
9 |
+
return func
|
10 |
+
return decorator
|
11 |
+
spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})()
|
12 |
+
HF_SPACES = False
|
13 |
+
print("Warning: Running without Hugging Face Spaces GPU allocation")
|
14 |
+
|
15 |
+
# ===== Now import other libraries =====
|
16 |
import random
|
17 |
import os
|
18 |
import uuid
|
|
|
27 |
from diffusers import DiffusionPipeline
|
28 |
from PIL import Image
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# ===== OpenAI ์ค์ =====
|
31 |
from openai import OpenAI
|
32 |
|
|
|
80 |
# ===== ๋ฒ์ญ & ์ฆ๊ฐ ํจ์ =====
|
81 |
|
82 |
def openai_translate(text: str, retries: int = 3) -> str:
|
83 |
+
"""ํ๊ธ์ ์์ด๋ก ๋ฒ์ญ (OpenAI GPT-4o-mini ์ฌ์ฉ). ์์ด ์
๋ ฅ์ด๋ฉด ๊ทธ๋๋ก ๋ฐํ."""
|
84 |
if not is_korean(text):
|
85 |
return text
|
86 |
|
|
|
91 |
for attempt in range(retries):
|
92 |
try:
|
93 |
res = client.chat.completions.create(
|
94 |
+
model="gpt-4o-mini",
|
95 |
messages=[
|
96 |
{
|
97 |
"role": "system",
|