video / app.py
seawolf2357's picture
Update app.py
b59f0da verified
raw
history blame
890 Bytes
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)