File size: 890 Bytes
b59f0da
5b0e95f
a0b6e16
b59f0da
 
b8bab42
b59f0da
 
 
 
 
 
 
 
 
 
 
3bdb854
b59f0da
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import openai
import os

# OpenAI API ν‚€ μ„€μ •
openai.api_key = os.getenv("OPENAI_API_KEY")  # ν™˜κ²½ λ³€μˆ˜μ—μ„œ API ν‚€λ₯Ό λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.

def generate_keywords_with_gpt(scene_descriptions):
    responses = []
    for description in scene_descriptions:
        response = openai.Completion.create(
            engine="text-davinci-003",  # ν˜Ήμ€ λ‹€λ₯Έ GPT λͺ¨λΈμ„ 선택할 수 μžˆμŠ΅λ‹ˆλ‹€.
            prompt=f"Generate a representative keyword for the following scene description: {description}",
            max_tokens=60,  # ν•„μš”ν•œ 토큰 수λ₯Ό μ‘°μ ˆν•  수 μžˆμŠ΅λ‹ˆλ‹€.
            temperature=0.7
        )
        responses.append(response.choices[0].text.strip())
    return responses

# μ‚¬μš© μ˜ˆμ‹œ
scene_descriptions = ["Enter description for Scene 1", "Enter description for Scene 2"]
keywords = generate_keywords_with_gpt(scene_descriptions)
print(keywords)