Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,25 @@
|
|
1 |
-
import gradio as gr
|
2 |
import openai
|
3 |
import os
|
4 |
|
5 |
-
#
|
6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
-
|
9 |
def generate_keyword_from_text(input_text):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
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="
|
33 |
outputs="text",
|
34 |
-
title="Generate Pexels Search Keyword with GPT
|
35 |
-
description="
|
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()
|