Rooni commited on
Commit
e177d94
·
1 Parent(s): 1121f22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
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
- return f'Ошибка при декодировании JSON: {str(e)}'
 
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
- return f'Ошибка: {error_message}'
 
32
  else:
33
- return f'Не удалось сгенерировать пост. {data}'
 
34
  else:
35
- return f'Ошибка при получении данных от сервера. Статус код: {response.status_code}'
 
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()