seawolf2357 commited on
Commit
79eed57
β€’
1 Parent(s): 53d3deb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -1,24 +1,25 @@
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
-
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
@@ -29,10 +30,10 @@ def gradio_interface(input_text):
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()
 
 
1
  import openai
2
  import os
3
 
4
+ # OpenAI API ν‚€ μ„€μ •
5
  openai.api_key = os.getenv("OPENAI_API_KEY")
6
 
 
7
  def generate_keyword_from_text(input_text):
8
+ try:
9
+ response = openai.Completion.create(
10
+ model="text-davinci-003", # GPT-4 λͺ¨λΈλͺ…을 적절히 μ„ νƒν•˜μ„Έμš”
11
+ prompt=f"Given the following text, generate a relevant English keyword for Pexels search: '{input_text}'",
12
+ temperature=0.5,
13
+ max_tokens=10,
14
+ top_p=1.0,
15
+ frequency_penalty=0.0,
16
+ presence_penalty=0.0
17
+ )
18
+ keyword = response.choices[0].text.strip()
19
+ return keyword
20
+ except Exception as e:
21
+ print(f"An error occurred: {e}")
22
+ return "Error generating keyword"
23
 
24
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ˜ˆμ‹œ
25
  import gradio as gr
 
30
 
31
  iface = gr.Interface(
32
  fn=gradio_interface,
33
+ inputs=gr.inputs.Textbox(lines=2, label="Enter Text"),
34
  outputs="text",
35
+ title="Generate Pexels Search Keyword with GPT",
36
+ description="This tool generates a keyword for Pexels search based on the provided text input."
37
  )
38
 
39
+ iface.launch()