ginipick commited on
Commit
1bd33f6
Β·
verified Β·
1 Parent(s): bf10941

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +14 -22
ui/components.py CHANGED
@@ -25,7 +25,7 @@ client = OpenAI(api_key=os.getenv("LLM_API"))
25
 
26
  def openai_generate_lyrics(topic: str) -> str:
27
  """
28
- 주제(topic)λ₯Ό λ°›μ•„ GPT-4.1-mini둜 [verse]/[chorus]/[bridge] ν˜•μ‹μ˜
29
  가사λ₯Ό 생성해 λ°˜ν™˜ν•œλ‹€. μ΅œλŒ€ 3회 μž¬μ‹œλ„ν•œλ‹€.
30
  """
31
  system_prompt = (
@@ -47,42 +47,34 @@ def openai_generate_lyrics(topic: str) -> str:
47
  retries = 3
48
  for attempt in range(retries):
49
  try:
50
- response = client.responses.create(
51
- model="gpt-4.1-mini",
52
- input=[
 
53
  {
54
  "role": "system",
55
- "content": [{"type": "input_text", "text": system_prompt}]
56
  },
57
  {
58
  "role": "user",
59
- "content": [{"type": "input_text", "text": topic}]
60
  }
61
  ],
62
- text={"format": {"type": "text"}},
63
- reasoning={},
64
- tools=[],
65
  temperature=1,
66
- max_output_tokens=2048,
67
- top_p=1,
68
- store=True
69
  )
70
 
71
- # assistant λ©”μ‹œμ§€μ—μ„œ 가사 ν…μŠ€νŠΈ μΆ”μΆœ
72
- msgs = response.get("input", [])
73
- if msgs and msgs[-1].get("role") == "assistant":
74
- contents = msgs[-1].get("content", [])
75
- if contents and contents[0].get("type") == "output_text":
76
- return contents[0]["text"]
77
 
78
- # ν˜•μ‹μ΄ μ˜ˆμƒκ³Ό λ‹€λ₯΄λ©΄ μ˜ˆμ™Έ λ°œμƒμ‹œμΌœ μž¬μ‹œλ„
79
- raise ValueError("Unexpected response structure")
80
-
81
- except (requests.exceptions.RequestException, Exception) as e:
82
  print(f"Attempt {attempt + 1}/{retries} failed: {e}")
83
  time.sleep(2)
84
 
85
  return "가사 생성 μ‹€νŒ¨: μž¬μ‹œλ„ λΆˆκ°€"
 
 
86
 
87
  TAG_DEFAULT = "funk, pop, soul, rock, melodic, guitar, drums, bass, keyboard, percussion, 105 BPM, energetic, upbeat, groovy, vibrant, dynamic"
88
  LYRIC_DEFAULT = """[verse]
 
25
 
26
  def openai_generate_lyrics(topic: str) -> str:
27
  """
28
+ 주제(topic)λ₯Ό λ°›μ•„ GPT-4둜 [verse]/[chorus]/[bridge] ν˜•μ‹μ˜
29
  가사λ₯Ό 생성해 λ°˜ν™˜ν•œλ‹€. μ΅œλŒ€ 3회 μž¬μ‹œλ„ν•œλ‹€.
30
  """
31
  system_prompt = (
 
47
  retries = 3
48
  for attempt in range(retries):
49
  try:
50
+ # ν‘œμ€€ OpenAI API ν˜•μ‹μœΌλ‘œ λ³€κ²½
51
+ response = client.chat.completions.create(
52
+ model="gpt-4.1-mini", # λ˜λŠ” "gpt-3.5-turbo"
53
+ messages=[
54
  {
55
  "role": "system",
56
+ "content": system_prompt
57
  },
58
  {
59
  "role": "user",
60
+ "content": topic
61
  }
62
  ],
 
 
 
63
  temperature=1,
64
+ max_tokens=2048,
65
+ top_p=1
 
66
  )
67
 
68
+ # ν‘œμ€€ 응닡 ν˜•μ‹μ—μ„œ ν…μŠ€νŠΈ μΆ”μΆœ
69
+ return response.choices[0].message.content
 
 
 
 
70
 
71
+ except Exception as e:
 
 
 
72
  print(f"Attempt {attempt + 1}/{retries} failed: {e}")
73
  time.sleep(2)
74
 
75
  return "가사 생성 μ‹€νŒ¨: μž¬μ‹œλ„ λΆˆκ°€"
76
+
77
+
78
 
79
  TAG_DEFAULT = "funk, pop, soul, rock, melodic, guitar, drums, bass, keyboard, percussion, 105 BPM, energetic, upbeat, groovy, vibrant, dynamic"
80
  LYRIC_DEFAULT = """[verse]