Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,22 +33,20 @@ def get_random_item(candidates):
|
|
| 33 |
|
| 34 |
def generate_natural_language_description(tags, api_key=None):
|
| 35 |
"""
|
| 36 |
-
|
| 37 |
"""
|
| 38 |
if api_key:
|
| 39 |
try:
|
| 40 |
openai.api_key = api_key.strip()
|
| 41 |
response = openai.ChatCompletion.create(
|
| 42 |
-
model="gpt-
|
| 43 |
messages=[
|
| 44 |
{"role": "system", "content": (
|
| 45 |
"You are a helpful assistant that generates creative painting/prompt descriptions. "
|
| 46 |
"Write at least three sentences in English, separated by periods."
|
| 47 |
)},
|
| 48 |
{"role": "user", "content": f"Here are the tags: {tags}\nPlease generate a vivid, imaginative scene description."}
|
| 49 |
-
]
|
| 50 |
-
max_tokens=300,
|
| 51 |
-
temperature=0.7,
|
| 52 |
)
|
| 53 |
return response["choices"][0]["message"]["content"].strip()
|
| 54 |
except Exception as e:
|
|
@@ -97,7 +95,8 @@ def generate_prompt(action_file, style_file, artist_files, character_files, api_
|
|
| 97 |
# ่ฟๅ็ปๆ
|
| 98 |
tags_list = [value for value in tags.values() if value]
|
| 99 |
final_tags = ", ".join(tags_list)
|
| 100 |
-
|
|
|
|
| 101 |
|
| 102 |
# ========== Gradio ็้ข ==========
|
| 103 |
def gradio_interface():
|
|
@@ -133,6 +132,7 @@ def gradio_interface():
|
|
| 133 |
with gr.Row():
|
| 134 |
tags_output = gr.Textbox(label="Generated Tags")
|
| 135 |
description_output = gr.Textbox(label="Generated Description")
|
|
|
|
| 136 |
|
| 137 |
# ๆ้ฎ
|
| 138 |
generate_button = gr.Button("Generate Prompt")
|
|
@@ -141,7 +141,7 @@ def gradio_interface():
|
|
| 141 |
generate_button.click(
|
| 142 |
generate_prompt,
|
| 143 |
inputs=[action_file, style_file, artist_files, character_files, api_key_input, selected_categories],
|
| 144 |
-
outputs=[tags_output, description_output],
|
| 145 |
)
|
| 146 |
|
| 147 |
return demo
|
|
|
|
| 33 |
|
| 34 |
def generate_natural_language_description(tags, api_key=None):
|
| 35 |
"""
|
| 36 |
+
ไฝฟ็จ OpenAI GPT ็ๆ่ช็ถ่ฏญ่จๆ่ฟฐ๏ผ้้
GPT-4o๏ผใ
|
| 37 |
"""
|
| 38 |
if api_key:
|
| 39 |
try:
|
| 40 |
openai.api_key = api_key.strip()
|
| 41 |
response = openai.ChatCompletion.create(
|
| 42 |
+
model="gpt-4",
|
| 43 |
messages=[
|
| 44 |
{"role": "system", "content": (
|
| 45 |
"You are a helpful assistant that generates creative painting/prompt descriptions. "
|
| 46 |
"Write at least three sentences in English, separated by periods."
|
| 47 |
)},
|
| 48 |
{"role": "user", "content": f"Here are the tags: {tags}\nPlease generate a vivid, imaginative scene description."}
|
| 49 |
+
]
|
|
|
|
|
|
|
| 50 |
)
|
| 51 |
return response["choices"][0]["message"]["content"].strip()
|
| 52 |
except Exception as e:
|
|
|
|
| 95 |
# ่ฟๅ็ปๆ
|
| 96 |
tags_list = [value for value in tags.values() if value]
|
| 97 |
final_tags = ", ".join(tags_list)
|
| 98 |
+
combined_output = f"Tags: {final_tags}\n\nDescription: {description}"
|
| 99 |
+
return final_tags, description, combined_output
|
| 100 |
|
| 101 |
# ========== Gradio ็้ข ==========
|
| 102 |
def gradio_interface():
|
|
|
|
| 132 |
with gr.Row():
|
| 133 |
tags_output = gr.Textbox(label="Generated Tags")
|
| 134 |
description_output = gr.Textbox(label="Generated Description")
|
| 135 |
+
combined_output = gr.Textbox(label="Combined Output: Tags + Description")
|
| 136 |
|
| 137 |
# ๆ้ฎ
|
| 138 |
generate_button = gr.Button("Generate Prompt")
|
|
|
|
| 141 |
generate_button.click(
|
| 142 |
generate_prompt,
|
| 143 |
inputs=[action_file, style_file, artist_files, character_files, api_key_input, selected_categories],
|
| 144 |
+
outputs=[tags_output, description_output, combined_output],
|
| 145 |
)
|
| 146 |
|
| 147 |
return demo
|