haohsiang commited on
Commit
3617874
·
1 Parent(s): 5174958

update OpenAI API settings

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -29,7 +29,7 @@ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.conf
29
  lora_path = "./tbh368-sdxl.safetensors"
30
  pipe.load_lora_weights(lora_path, adapter_name="milton-glaser")
31
  pipe.load_lora_weights("e-n-v-y/envyimpressionismxl01", weight_name="EnvyImpressionismXL01.safetensors", adapter_name="impressionism")
32
- pipe.set_adapters(["milton-glaser", "impressionism"], adapter_weights=[0.8, 0.6])
33
 
34
  # 載入 CVAW Corpus 資料
35
  cvaw_data = pd.read_csv('./CVAW_all_SD.csv', delimiter='\t')
@@ -65,7 +65,7 @@ def call_gpt(input_text, history):
65
  messages.append({"role": "user", "content": input_text})
66
 
67
  chat_reply = client.chat.completions.create(
68
- model="gpt-4o",
69
  messages=messages,
70
  temperature=0.8
71
  )
@@ -104,7 +104,9 @@ def translate_to_english(text):
104
 
105
  chat_reply = client.chat.completions.create(
106
  messages=messages,
107
- model="gpt-4o-mini",
 
 
108
  )
109
 
110
  return chat_reply.choices[0].message.content
@@ -117,7 +119,7 @@ def generate_images(history, conversation_times, last_genimg_times, generated_im
117
  user_story = " ".join([h[0] for h in history])
118
  prompt = translate_to_english(user_story)
119
 
120
- neg_prompt = "dark, realistic, words, sentence, text, Low quality, error, extra, nude, duplicate, ugly"
121
 
122
  seeds = np.random.randint(0, 100000, 4)
123
  generator = [torch.Generator().manual_seed(int(i)) for i in seeds]
@@ -125,7 +127,7 @@ def generate_images(history, conversation_times, last_genimg_times, generated_im
125
  last_genimg_times = conversation_times
126
 
127
  for i in range(4):
128
- img = pipe("modern digital impressionism, style of Milton Glaser, oil painting, moody color palette, hard to understood, "+prompt,
129
  negative_prompt=neg_prompt,
130
  height=720, width=512,
131
  generator=generator[i],
@@ -156,7 +158,7 @@ def chat_about_image(input_text, history, selected_image):
156
  ]
157
 
158
  chat_reply = client.chat.completions.create(
159
- model="gpt-4o",
160
  messages=messages,
161
  max_tokens=300
162
  )
@@ -287,7 +289,7 @@ with gr.Blocks(theme=theme, css=css, title='療癒對話機器人') as demo:
287
  arousal_scores = gr.State(value=[])
288
 
289
  gr.Markdown("# 療癒對話機器人")
290
- gr.LoginButton(value="登入 HuggingFace", logout_value="登出", variant="primary", size="sm")
291
 
292
  loading_message = gr.Textbox(visible=False, show_label=False)
293
  with gr.Column(visible=False) as audio_interface:
@@ -313,6 +315,7 @@ with gr.Blocks(theme=theme, css=css, title='療癒對話機器人') as demo:
313
  image_chat_input = gr.Textbox(label="這張圖像讓你產生了什麼樣的聯想?")
314
  image_chat_button = gr.Button("與聊天機器人分享", variant="primary")
315
 
 
316
  # chatbot events handle
317
  submit.click(handle_chat, [msg, chatbot, conversation_times, valence_scores, arousal_scores, meditation_flag], [chatbot, msg, submit, jump_to_med, meditation_buttons, conversation_times, valence_scores, arousal_scores, meditation_flag])
318
  msg.submit(handle_chat, [msg, chatbot, conversation_times, valence_scores, arousal_scores, meditation_flag], [chatbot, msg, submit, jump_to_med, meditation_buttons, conversation_times, valence_scores, arousal_scores, meditation_flag])
@@ -339,4 +342,4 @@ with gr.Blocks(theme=theme, css=css, title='療癒對話機器人') as demo:
339
 
340
  if __name__ == "__main__":
341
  demo.queue(max_size=30, default_concurrency_limit=20)
342
- demo.launch(show_api=False, max_threads=40)
 
29
  lora_path = "./tbh368-sdxl.safetensors"
30
  pipe.load_lora_weights(lora_path, adapter_name="milton-glaser")
31
  pipe.load_lora_weights("e-n-v-y/envyimpressionismxl01", weight_name="EnvyImpressionismXL01.safetensors", adapter_name="impressionism")
32
+ pipe.set_adapters(["milton-glaser", "impressionism"], adapter_weights=[0.9, 0.6])
33
 
34
  # 載入 CVAW Corpus 資料
35
  cvaw_data = pd.read_csv('./CVAW_all_SD.csv', delimiter='\t')
 
65
  messages.append({"role": "user", "content": input_text})
66
 
67
  chat_reply = client.chat.completions.create(
68
+ model="chatgpt-4o-latest",
69
  messages=messages,
70
  temperature=0.8
71
  )
 
104
 
105
  chat_reply = client.chat.completions.create(
106
  messages=messages,
107
+ model="chatgpt-4o-latest",
108
+ temperature=0.3,
109
+ max_tokens=60
110
  )
111
 
112
  return chat_reply.choices[0].message.content
 
119
  user_story = " ".join([h[0] for h in history])
120
  prompt = translate_to_english(user_story)
121
 
122
+ neg_prompt = "dark, realistic, words, sentence, text, extra, nude, duplicate, ugly"
123
 
124
  seeds = np.random.randint(0, 100000, 4)
125
  generator = [torch.Generator().manual_seed(int(i)) for i in seeds]
 
127
  last_genimg_times = conversation_times
128
 
129
  for i in range(4):
130
+ img = pipe("modern digital impressionism, style of Milton Glaser, oil painting, moody color palette, hard to understood, abstract, "+prompt,
131
  negative_prompt=neg_prompt,
132
  height=720, width=512,
133
  generator=generator[i],
 
158
  ]
159
 
160
  chat_reply = client.chat.completions.create(
161
+ model="chatgpt-4o-latest",
162
  messages=messages,
163
  max_tokens=300
164
  )
 
289
  arousal_scores = gr.State(value=[])
290
 
291
  gr.Markdown("# 療癒對話機器人")
292
+ login = gr.LoginButton(value="登入 Hugging Face", logout_value="登出 Hugging Face", variant="primary", size="sm")
293
 
294
  loading_message = gr.Textbox(visible=False, show_label=False)
295
  with gr.Column(visible=False) as audio_interface:
 
315
  image_chat_input = gr.Textbox(label="這張圖像讓你產生了什麼樣的聯想?")
316
  image_chat_button = gr.Button("與聊天機器人分享", variant="primary")
317
 
318
+ login.activate()
319
  # chatbot events handle
320
  submit.click(handle_chat, [msg, chatbot, conversation_times, valence_scores, arousal_scores, meditation_flag], [chatbot, msg, submit, jump_to_med, meditation_buttons, conversation_times, valence_scores, arousal_scores, meditation_flag])
321
  msg.submit(handle_chat, [msg, chatbot, conversation_times, valence_scores, arousal_scores, meditation_flag], [chatbot, msg, submit, jump_to_med, meditation_buttons, conversation_times, valence_scores, arousal_scores, meditation_flag])
 
342
 
343
  if __name__ == "__main__":
344
  demo.queue(max_size=30, default_concurrency_limit=20)
345
+ demo.launch(show_api=False, max_threads=40)