PSNbst commited on
Commit
9730020
ยท
verified ยท
1 Parent(s): 1277cad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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
- ็”Ÿๆˆ่‡ช็„ถ่ฏญ่จ€ๆ่ฟฐ๏ผŒๅฏไปฅ้€‰ๆ‹ฉไฝฟ็”จ GPT ๆˆ–ๆ‰‹ๅ†™้€ป่พ‘ใ€‚
37
  """
38
  if api_key:
39
  try:
40
  openai.api_key = api_key.strip()
41
  response = openai.ChatCompletion.create(
42
- model="gpt-4o",
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
- return final_tags, description
 
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