Spaces:
Sleeping
Sleeping
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, | |
temperature=0.7 | |
) | |
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() | |