seawolf2357 commited on
Commit
eef17a1
Β·
verified Β·
1 Parent(s): ea5a551

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -1,22 +1,29 @@
 
1
  import openai
2
  import os
3
 
4
- # OpenAI API ν‚€ μ„€μ •
5
- openai.api_key = os.getenv("OPENAI_API_KEY") # ν™˜κ²½ λ³€μˆ˜μ—μ„œ API ν‚€λ₯Ό λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.
6
 
7
- def generate_keywords_with_gpt(scene_descriptions):
8
- responses = []
9
- for description in scene_descriptions:
10
- response = openai.Completion.create(
11
- engine="text-davinci-003", # ν˜Ήμ€ λ‹€λ₯Έ GPT λͺ¨λΈμ„ 선택할 수 μžˆμŠ΅λ‹ˆλ‹€.
12
- prompt=f"Generate a representative keyword for the following scene description: {description}",
13
- max_tokens=60, # ν•„μš”ν•œ 토큰 수λ₯Ό μ‘°μ ˆν•  수 μžˆμŠ΅λ‹ˆλ‹€.
14
- temperature=0.7
 
 
 
 
 
 
 
 
 
15
  )
16
- responses.append(response.choices[0].text.strip())
17
- return responses
18
 
19
- # μ‚¬μš© μ˜ˆμ‹œ
20
- scene_descriptions = ["Enter description for Scene 1", "Enter description for Scene 2"]
21
- keywords = generate_keywords_with_gpt(scene_descriptions)
22
- print(keywords)
 
1
+ import gradio as gr
2
  import openai
3
  import os
4
 
5
+ # ν™˜κ²½ λ³€μˆ˜μ—μ„œ OpenAI API ν‚€λ₯Ό λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
+ def generate_keywords(scene_description):
9
+ response = openai.Completion.create(
10
+ model="text-davinci-003",
11
+ prompt=f"Generate a representative English keyword for the following scene description: {scene_description}",
12
+ max_tokens=60
13
+ )
14
+ keyword = response.choices[0].text.strip()
15
+ return keyword
16
+
17
+ # Gradio μ•± μ •μ˜
18
+ def gradio_app():
19
+ with gr.Blocks() as demo:
20
+ with gr.Row():
21
+ scene_description = gr.Textbox(label="Scene Description")
22
+ keyword_output = gr.Textbox(label="Generated Keyword")
23
+ gr.Button("Generate Keyword").click(
24
+ generate_keywords, inputs=[scene_description], outputs=[keyword_output]
25
  )
26
+ return demo
 
27
 
28
+ app = gradio_app()
29
+ app.launch()