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