Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
)
|
15 |
-
keyword = response
|
16 |
-
return keyword
|
17 |
except Exception as e:
|
18 |
-
print(f"
|
19 |
-
return "
|
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=
|
30 |
-
inputs=gr.Textbox(lines=2, label="
|
31 |
outputs="text",
|
32 |
-
title="
|
33 |
-
description="
|
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 |
# μΈν°νμ΄μ€ μ€ν
|