Spaces:
Sleeping
Sleeping
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() |