seawolf2357 commited on
Commit
e14d9c5
ยท
verified ยท
1 Parent(s): 87f4386

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
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-4.1-mini ์‚ฌ์šฉ). ์˜์–ด ์ž…๋ ฅ์ด๋ฉด ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜."""
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", # Fixed: gpt-4.1-mini doesn't exist, use 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",