File size: 1,183 Bytes
eef17a1
b59f0da
5b0e95f
a0b6e16
eef17a1
 
b8bab42
53d3deb
 
 
eef17a1
53d3deb
 
 
 
 
 
 
eef17a1
53d3deb
 
 
 
 
 
 
 
eef17a1
3bdb854
53d3deb
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
import openai
import os

# ν™˜κ²½ λ³€μˆ˜μ—μ„œ OpenAI API ν‚€λ₯Ό λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.
openai.api_key = os.getenv("OPENAI_API_KEY")


def generate_keyword_from_text(input_text):
    # GPT-4 λͺ¨λΈμ„ μ‚¬μš©ν•˜μ—¬ μž…λ ₯ ν…μŠ€νŠΈμ— κΈ°λ°˜ν•œ ν‚€μ›Œλ“œ 생성 μš”μ²­
    response = openai.Completion.create(
        model="text-davinci-004",  # GPT-4 λͺ¨λΈ μ§€μ • (ν˜„μž¬ GPT-4 λͺ¨λΈλͺ…이 'text-davinci-004'라고 κ°€μ •)
        prompt=f"Given the following text, generate a relevant English keyword for Pexels search: '{input_text}'",
        temperature=0.5,
        max_tokens=10,
        top_p=1.0,
        frequency_penalty=0.0,
        presence_penalty=0.0
    )
    # μƒμ„±λœ ν‚€μ›Œλ“œ λ°˜ν™˜
    return response.choices[0].text.strip()

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ˜ˆμ‹œ
import gradio as gr

def gradio_interface(input_text):
    keyword = generate_keyword_from_text(input_text)
    return keyword

iface = gr.Interface(
    fn=gradio_interface,
    inputs="text",
    outputs="text",
    title="Generate Pexels Search Keyword with GPT-4",
    description="Enter some text and generate a relevant English keyword for searching on Pexels."
)

iface.launch()