seawolf2357 commited on
Commit
24742bd
Β·
verified Β·
1 Parent(s): 1dc42f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -7,30 +7,28 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
  def generate_keyword_from_text(input_text):
9
  try:
10
- response = openai.ChatCompletion.create(
11
- model="gpt-3.5-turbo", # ν˜„μž¬ μ‚¬μš© κ°€λŠ₯ν•œ GPT λͺ¨λΈλͺ…μœΌλ‘œ μ—…λ°μ΄νŠΈν•˜μ„Έμš”.
12
- messages=[{"role": "system", "content": "Generate a relevant English keyword for the following description."},
13
- {"role": "user", "content": f"{input_text}"}]
 
 
14
  )
15
- keyword = response['choices'][0]['message']['content']
16
- return keyword.strip()
17
  except Exception as e:
18
- print(f"An error occurred: {e}")
19
- return "Error generating keyword"
20
-
21
- def gradio_interface(input_text):
22
- keyword = generate_keyword_from_text(input_text)
23
- return keyword
24
 
25
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
26
  import gradio as gr
27
 
28
  iface = gr.Interface(
29
- fn=gradio_interface,
30
- inputs=gr.Textbox(lines=2, label="Enter Text"),
31
  outputs="text",
32
- title="Generate Pexels Search Keyword with GPT",
33
- description="This tool generates a keyword for Pexels search based on the provided text input."
34
  )
35
 
36
  # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
 
7
 
8
  def generate_keyword_from_text(input_text):
9
  try:
10
+ # μ΅œμ‹  OpenAI APIλ₯Ό μ‚¬μš©ν•˜μ—¬ ν…μŠ€νŠΈ μ™„μ„± μš”μ²­
11
+ response = openai.Completion.create(
12
+ model="text-davinci-003", # μ‚¬μš© κ°€λŠ₯ν•œ GPT-3 λͺ¨λΈ
13
+ prompt=f"λ‹€μŒ ν…μŠ€νŠΈμ— λŒ€ν•œ Pexels 검색을 μœ„ν•œ 영문 ν‚€μ›Œλ“œ 생성: '{input_text}'",
14
+ temperature=0.5,
15
+ max_tokens=10
16
  )
17
+ keyword = response.choices[0].text.strip()
18
+ return keyword
19
  except Exception as e:
20
+ print(f"μ—λŸ¬ λ°œμƒ: {e}")
21
+ return "ν‚€μ›Œλ“œ 생성 쀑 μ—λŸ¬ λ°œμƒ"
 
 
 
 
22
 
23
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
24
  import gradio as gr
25
 
26
  iface = gr.Interface(
27
+ fn=generate_keyword_from_text,
28
+ inputs=gr.Textbox(lines=2, label="ν…μŠ€νŠΈ μž…λ ₯"),
29
  outputs="text",
30
+ title="GPTλ₯Ό μ΄μš©ν•œ Pexels 검색 ν‚€μ›Œλ“œ 생성",
31
+ description="제곡된 ν…μŠ€νŠΈλ₯Ό λ°”νƒ•μœΌλ‘œ Pexels 검색에 μ‚¬μš©ν•  영문 ν‚€μ›Œλ“œλ₯Ό μžλ™ μƒμ„±ν•©λ‹ˆλ‹€."
32
  )
33
 
34
  # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰