Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,29 @@
|
|
|
|
1 |
import openai
|
2 |
import os
|
3 |
|
4 |
-
# OpenAI API
|
5 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
)
|
16 |
-
|
17 |
-
return responses
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
keywords = generate_keywords_with_gpt(scene_descriptions)
|
22 |
-
print(keywords)
|
|
|
1 |
+
import gradio as gr
|
2 |
import openai
|
3 |
import os
|
4 |
|
5 |
+
# νκ²½ λ³μμμ OpenAI API ν€λ₯Ό λΆλ¬μ΅λλ€.
|
6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
+
def generate_keywords(scene_description):
|
9 |
+
response = openai.Completion.create(
|
10 |
+
model="text-davinci-003",
|
11 |
+
prompt=f"Generate a representative English keyword for the following scene description: {scene_description}",
|
12 |
+
max_tokens=60
|
13 |
+
)
|
14 |
+
keyword = response.choices[0].text.strip()
|
15 |
+
return keyword
|
16 |
+
|
17 |
+
# Gradio μ± μ μ
|
18 |
+
def gradio_app():
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
with gr.Row():
|
21 |
+
scene_description = gr.Textbox(label="Scene Description")
|
22 |
+
keyword_output = gr.Textbox(label="Generated Keyword")
|
23 |
+
gr.Button("Generate Keyword").click(
|
24 |
+
generate_keywords, inputs=[scene_description], outputs=[keyword_output]
|
25 |
)
|
26 |
+
return demo
|
|
|
27 |
|
28 |
+
app = gradio_app()
|
29 |
+
app.launch()
|
|
|
|