Spaces:
Running
on
Zero
Running
on
Zero
Update ui/components.py
Browse files- 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
|
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 |
-
|
51 |
-
|
52 |
-
|
|
|
53 |
{
|
54 |
"role": "system",
|
55 |
-
"content":
|
56 |
},
|
57 |
{
|
58 |
"role": "user",
|
59 |
-
"content":
|
60 |
}
|
61 |
],
|
62 |
-
text={"format": {"type": "text"}},
|
63 |
-
reasoning={},
|
64 |
-
tools=[],
|
65 |
temperature=1,
|
66 |
-
|
67 |
-
top_p=1
|
68 |
-
store=True
|
69 |
)
|
70 |
|
71 |
-
#
|
72 |
-
|
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]
|