seawolf2357 commited on
Commit
53d3deb
·
verified ·
1 Parent(s): e828a66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -5,26 +5,34 @@ import os
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
- temperature=0.7
 
 
 
14
  )
15
- keyword = response.choices[0].text.strip()
 
 
 
 
 
 
 
16
  return keyword
17
-
18
- # Gradio 앱 정의
19
- def gradio_app():
20
- with gr.Blocks() as demo:
21
- with gr.Row():
22
- scene_description = gr.Textbox(label="Scene Description")
23
- keyword_output = gr.Textbox(label="Generated Keyword")
24
- gr.Button("Generate Keyword").click(
25
- generate_keywords, inputs=[scene_description], outputs=[keyword_output]
26
- )
27
- return demo
28
 
29
- app = gradio_app()
30
- app.launch()
 
 
 
 
 
 
 
 
5
  # 환경 변수에서 OpenAI API 키를 불러옵니다.
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
+
9
+ def generate_keyword_from_text(input_text):
10
+ # GPT-4 모델을 사용하여 입력 텍스트에 기반한 키워드 생성 요청
11
  response = openai.Completion.create(
12
+ model="text-davinci-004", # GPT-4 모델 지정 (현재 GPT-4 모델명이 'text-davinci-004'라고 가정)
13
+ prompt=f"Given the following text, generate a relevant English keyword for Pexels search: '{input_text}'",
14
+ temperature=0.5,
15
+ max_tokens=10,
16
+ top_p=1.0,
17
+ frequency_penalty=0.0,
18
+ presence_penalty=0.0
19
  )
20
+ # 생성된 키워드 반환
21
+ return response.choices[0].text.strip()
22
+
23
+ # Gradio 인터페이스 예시
24
+ import gradio as gr
25
+
26
+ def gradio_interface(input_text):
27
+ keyword = generate_keyword_from_text(input_text)
28
  return keyword
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ iface = gr.Interface(
31
+ fn=gradio_interface,
32
+ inputs="text",
33
+ outputs="text",
34
+ title="Generate Pexels Search Keyword with GPT-4",
35
+ description="Enter some text and generate a relevant English keyword for searching on Pexels."
36
+ )
37
+
38
+ iface.launch()