Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,17 +7,13 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
7 |
|
8 |
def generate_keyword_from_text(input_text):
|
9 |
try:
|
10 |
-
response = openai.
|
11 |
-
model="
|
12 |
-
|
13 |
-
|
14 |
-
max_tokens=10,
|
15 |
-
top_p=1.0,
|
16 |
-
frequency_penalty=0.0,
|
17 |
-
presence_penalty=0.0
|
18 |
)
|
19 |
-
keyword = response
|
20 |
-
return keyword
|
21 |
except Exception as e:
|
22 |
print(f"An error occurred: {e}")
|
23 |
return "Error generating keyword"
|
@@ -26,12 +22,16 @@ def gradio_interface(input_text):
|
|
26 |
keyword = generate_keyword_from_text(input_text)
|
27 |
return keyword
|
28 |
|
|
|
|
|
|
|
29 |
iface = gr.Interface(
|
30 |
fn=gradio_interface,
|
31 |
-
inputs=gr.Textbox(lines=2, label="Enter Text"),
|
32 |
outputs="text",
|
33 |
title="Generate Pexels Search Keyword with GPT",
|
34 |
description="This tool generates a keyword for Pexels search based on the provided text input."
|
35 |
)
|
36 |
|
|
|
37 |
iface.launch()
|
|
|
7 |
|
8 |
def generate_keyword_from_text(input_text):
|
9 |
try:
|
10 |
+
response = openai.ChatCompletion.create(
|
11 |
+
model="gpt-3.5-turbo", # ํ์ฌ ์ฌ์ฉ ๊ฐ๋ฅํ GPT ๋ชจ๋ธ๋ช
์ผ๋ก ์
๋ฐ์ดํธํ์ธ์.
|
12 |
+
messages=[{"role": "system", "content": "Generate a relevant English keyword for the following description."},
|
13 |
+
{"role": "user", "content": f"{input_text}"}]
|
|
|
|
|
|
|
|
|
14 |
)
|
15 |
+
keyword = response['choices'][0]['message']['content']
|
16 |
+
return keyword.strip()
|
17 |
except Exception as e:
|
18 |
print(f"An error occurred: {e}")
|
19 |
return "Error generating keyword"
|
|
|
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=gradio_interface,
|
30 |
+
inputs=gr.Textbox(lines=2, label="Enter Text"),
|
31 |
outputs="text",
|
32 |
title="Generate Pexels Search Keyword with GPT",
|
33 |
description="This tool generates a keyword for Pexels search based on the provided text input."
|
34 |
)
|
35 |
|
36 |
+
# ์ธํฐํ์ด์ค ์คํ
|
37 |
iface.launch()
|