Update app.py
Browse files
app.py
CHANGED
@@ -21,21 +21,25 @@ def dzen(theme, description=""):
|
|
21 |
try:
|
22 |
data = response.json()
|
23 |
except json.decoder.JSONDecodeError as e:
|
24 |
-
|
|
|
25 |
|
26 |
if 'choices' in data and len(data['choices']) > 0:
|
27 |
command = data['choices'][0]['message']['content'].strip()
|
28 |
return command
|
29 |
elif 'error' in data:
|
30 |
error_message = data['error']['message']
|
31 |
-
|
|
|
32 |
else:
|
33 |
-
|
|
|
34 |
else:
|
35 |
-
|
|
|
36 |
|
37 |
iface = gr.Interface(fn=dzen, inputs=[
|
38 |
gr.Textbox(label="Тема", placeholder=""),
|
39 |
gr.Textbox(label="Дополнительный текст")
|
40 |
], outputs=gr.Textbox(label="Пост"), title="Генератор постов Яндекс Дзен")
|
41 |
-
iface.launch()
|
|
|
21 |
try:
|
22 |
data = response.json()
|
23 |
except json.decoder.JSONDecodeError as e:
|
24 |
+
gr.alert(f'Ошибка при декодировании JSON: {str(e)}')
|
25 |
+
return ''
|
26 |
|
27 |
if 'choices' in data and len(data['choices']) > 0:
|
28 |
command = data['choices'][0]['message']['content'].strip()
|
29 |
return command
|
30 |
elif 'error' in data:
|
31 |
error_message = data['error']['message']
|
32 |
+
gr.alert(f'Ошибка: {error_message}')
|
33 |
+
return ''
|
34 |
else:
|
35 |
+
gr.alert(f'Не удалось сгенерировать пост. {data}')
|
36 |
+
return ''
|
37 |
else:
|
38 |
+
gr.alert(f'Ошибка при получении данных от сервера. Статус код: {response.status_code}')
|
39 |
+
return ''
|
40 |
|
41 |
iface = gr.Interface(fn=dzen, inputs=[
|
42 |
gr.Textbox(label="Тема", placeholder=""),
|
43 |
gr.Textbox(label="Дополнительный текст")
|
44 |
], outputs=gr.Textbox(label="Пост"), title="Генератор постов Яндекс Дзен")
|
45 |
+
iface.launch()
|