import gradio as gr import openai import os # 환경 변수에서 OpenAI API 키를 불러옵니다. openai.api_key = os.getenv("OPENAI_API_KEY") def generate_keywords(scene_description): response = openai.Completion.create( model="text-davinci-003", prompt=f"Generate a representative English keyword for the following scene description: {scene_description}", max_tokens=60 ) keyword = response.choices[0].text.strip() return keyword # Gradio 앱 정의 def gradio_app(): with gr.Blocks() as demo: with gr.Row(): scene_description = gr.Textbox(label="Scene Description") keyword_output = gr.Textbox(label="Generated Keyword") gr.Button("Generate Keyword").click( generate_keywords, inputs=[scene_description], outputs=[keyword_output] ) return demo app = gradio_app() app.launch()