Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -76,7 +76,7 @@ def generate_standard_prompt(description, advantages, *selected_values):
|
|
76 |
return prompt
|
77 |
|
78 |
# Функции для генерации сообщений
|
79 |
-
def generate_message_gpt4o(prompt):
|
80 |
try:
|
81 |
headers = {
|
82 |
"Content-Type": "application/json",
|
@@ -85,14 +85,16 @@ def generate_message_gpt4o(prompt):
|
|
85 |
data = {
|
86 |
"model": "chatgpt-4o-latest",
|
87 |
"messages": [{"role": "system", "content": prompt}],
|
88 |
-
"max_tokens": 101
|
|
|
89 |
}
|
90 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
91 |
response_data = response.json()
|
92 |
-
return response_data["choices"][0]["message"]["content"].strip()
|
93 |
except Exception as e:
|
94 |
return f"Ошибка при обращении к ChatGPT-4o-Latest: {e}"
|
95 |
|
|
|
96 |
def clean_message(message):
|
97 |
# Если сообщение не заканчивается на точку или восклицательный знак, обрезаем его до последней точки
|
98 |
if not message.endswith(('.', '!', '?')):
|
@@ -102,29 +104,32 @@ def clean_message(message):
|
|
102 |
return message
|
103 |
|
104 |
# Обновленные функции генерации сообщений с учетом обрезки незаконченных предложений
|
105 |
-
def generate_message_gigachat_pro(prompt):
|
106 |
try:
|
107 |
messages = [SystemMessage(content=prompt)]
|
|
|
108 |
res = chat_pro(messages)
|
109 |
cleaned_message = clean_message(res.content.strip())
|
110 |
return cleaned_message
|
111 |
except Exception as e:
|
112 |
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
113 |
|
114 |
-
def generate_message_gigachat_lite(prompt):
|
115 |
try:
|
116 |
time.sleep(2)
|
117 |
messages = [SystemMessage(content=prompt)]
|
|
|
118 |
res = chat_lite(messages)
|
119 |
cleaned_message = clean_message(res.content.strip())
|
120 |
return cleaned_message
|
121 |
except Exception as e:
|
122 |
return f"Ошибка при обращении к GigaChat-Lite: {e}"
|
123 |
|
124 |
-
def generate_message_gigachat_plus(prompt):
|
125 |
try:
|
126 |
time.sleep(2)
|
127 |
messages = [SystemMessage(content=prompt)]
|
|
|
128 |
res = chat_plus(messages)
|
129 |
cleaned_message = clean_message(res.content.strip())
|
130 |
return cleaned_message
|
@@ -346,10 +351,11 @@ def check_errors_with_yield(*personalized_messages):
|
|
346 |
yield error_check_prompt, error_message_gpt4o, error_message_gigachat_pro, error_message_gigachat_lite, error_message_gigachat_plus, "Все результаты проверки сгенерированы"
|
347 |
|
348 |
|
349 |
-
def save_to_github(personalized_message, model_name, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form):
|
350 |
# Собираем все данные в один словарь
|
351 |
data_to_save = {
|
352 |
"Модель": model_name,
|
|
|
353 |
"Персонализированное сообщение": personalized_message,
|
354 |
"Комментарий": comment,
|
355 |
"Откорректированное сообщение": corrected_message,
|
@@ -385,9 +391,17 @@ def save_to_github(personalized_message, model_name, comment, corrected_message,
|
|
385 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
386 |
|
387 |
|
|
|
388 |
# Создание интерфейса Gradio
|
389 |
with gr.Blocks() as demo:
|
390 |
gr.Markdown("# Генерация SMS-сообщений по заданным признакам")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
|
392 |
with gr.Row():
|
393 |
with gr.Column(scale=1):
|
@@ -430,7 +444,15 @@ with gr.Blocks() as demo:
|
|
430 |
|
431 |
submit_btn.click(
|
432 |
generate_messages,
|
433 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
outputs=[prompt_display, output_text_gpt4o, output_text_gigachat_pro, output_text_gigachat_lite, output_text_gigachat_plus]
|
435 |
)
|
436 |
|
|
|
76 |
return prompt
|
77 |
|
78 |
# Функции для генерации сообщений
|
79 |
+
def generate_message_gpt4o(prompt, temperature=1):
|
80 |
try:
|
81 |
headers = {
|
82 |
"Content-Type": "application/json",
|
|
|
85 |
data = {
|
86 |
"model": "chatgpt-4o-latest",
|
87 |
"messages": [{"role": "system", "content": prompt}],
|
88 |
+
"max_tokens": 101,
|
89 |
+
"temperature": temperature # Передача температуры
|
90 |
}
|
91 |
response = requests.post("https://api.openai.com/v1/chat/completions", json=data, headers=headers)
|
92 |
response_data = response.json()
|
93 |
+
return clean_message(response_data["choices"][0]["message"]["content"].strip())
|
94 |
except Exception as e:
|
95 |
return f"Ошибка при обращении к ChatGPT-4o-Latest: {e}"
|
96 |
|
97 |
+
|
98 |
def clean_message(message):
|
99 |
# Если сообщение не заканчивается на точку или восклицательный знак, обрезаем его до последней точки
|
100 |
if not message.endswith(('.', '!', '?')):
|
|
|
104 |
return message
|
105 |
|
106 |
# Обновленные функции генерации сообщений с учетом обрезки незаконченных предложений
|
107 |
+
def generate_message_gigachat_pro(prompt, temperature=0.87):
|
108 |
try:
|
109 |
messages = [SystemMessage(content=prompt)]
|
110 |
+
chat_pro = GigaChat(credentials=gc_key, model='GigaChat-Pro', max_tokens=68, temperature=temperature, verify_ssl_certs=False)
|
111 |
res = chat_pro(messages)
|
112 |
cleaned_message = clean_message(res.content.strip())
|
113 |
return cleaned_message
|
114 |
except Exception as e:
|
115 |
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
116 |
|
117 |
+
def generate_message_gigachat_lite(prompt, temperature=0.87):
|
118 |
try:
|
119 |
time.sleep(2)
|
120 |
messages = [SystemMessage(content=prompt)]
|
121 |
+
chat_lite = GigaChat(credentials=gc_key, model='GigaChat', max_tokens=68, temperature=temperature, verify_ssl_certs=False)
|
122 |
res = chat_lite(messages)
|
123 |
cleaned_message = clean_message(res.content.strip())
|
124 |
return cleaned_message
|
125 |
except Exception as e:
|
126 |
return f"Ошибка при обращении к GigaChat-Lite: {e}"
|
127 |
|
128 |
+
def generate_message_gigachat_plus(prompt, temperature=0.87):
|
129 |
try:
|
130 |
time.sleep(2)
|
131 |
messages = [SystemMessage(content=prompt)]
|
132 |
+
chat_plus = GigaChat(credentials=gc_key, model='GigaChat-Plus', max_tokens=68, temperature=temperature, verify_ssl_certs=False)
|
133 |
res = chat_plus(messages)
|
134 |
cleaned_message = clean_message(res.content.strip())
|
135 |
return cleaned_message
|
|
|
351 |
yield error_check_prompt, error_message_gpt4o, error_message_gigachat_pro, error_message_gigachat_lite, error_message_gigachat_plus, "Все результаты проверки сгенерированы"
|
352 |
|
353 |
|
354 |
+
def save_to_github(personalized_message, model_name, comment, corrected_message, description, advantages, non_personalized_prompt, non_personalized_message, gender, generation, psychotype, business_stage, industry, legal_form, temperature):
|
355 |
# Собираем все данные в один словарь
|
356 |
data_to_save = {
|
357 |
"Модель": model_name,
|
358 |
+
"Температура": temperature, # Добавляем температуру
|
359 |
"Персонализированное сообщение": personalized_message,
|
360 |
"Комментарий": comment,
|
361 |
"Откорректированное сообщение": corrected_message,
|
|
|
391 |
response = requests.put(url, headers=headers, data=json.dumps(data))
|
392 |
|
393 |
|
394 |
+
|
395 |
# Создание интерфейса Gradio
|
396 |
with gr.Blocks() as demo:
|
397 |
gr.Markdown("# Генерация SMS-сообщений по заданным признакам")
|
398 |
+
|
399 |
+
# Добавление элементов управления температурой для каждой модели
|
400 |
+
gpt4o_temperature = gr.Slider(label="GPT-4o: temperature", minimum=0, maximum=1.7, step=0.01, value=1)
|
401 |
+
gigachat_pro_temperature = gr.Slider(label="GigaChat-Pro: temperature", minimum=0, maximum=1.7, step=0.01, value=0.87)
|
402 |
+
gigachat_lite_temperature = gr.Slider(label="GigaChat-Lite: temperature", minimum=0, maximum=1.7, step=0.01, value=0.87)
|
403 |
+
gigachat_plus_temperature = gr.Slider(label="GigaChat-Plus: temperature", minimum=0, maximum=1.7, step=0.01, value=0.87)
|
404 |
+
|
405 |
|
406 |
with gr.Row():
|
407 |
with gr.Column(scale=1):
|
|
|
444 |
|
445 |
submit_btn.click(
|
446 |
generate_messages,
|
447 |
+
inputs=[
|
448 |
+
description_input,
|
449 |
+
advantages_input,
|
450 |
+
*selections,
|
451 |
+
gpt4o_temperature,
|
452 |
+
gigachat_pro_temperature,
|
453 |
+
gigachat_lite_temperature,
|
454 |
+
gigachat_plus_temperature
|
455 |
+
],
|
456 |
outputs=[prompt_display, output_text_gpt4o, output_text_gigachat_pro, output_text_gigachat_lite, output_text_gigachat_plus]
|
457 |
)
|
458 |
|