Rooni commited on
Commit
5395fc0
1 Parent(s): c795977

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import requests
3
  import json
4
  import os
 
5
 
6
  def generate(description, model, max_tokens):
7
  headers = {
@@ -15,21 +16,17 @@ def generate(description, model, max_tokens):
15
  'model': model
16
  }
17
 
18
- response = requests.post(os.getenv("BASE_URL"), headers=headers, json=payload)
19
- data = json.loads(response.text)
 
20
 
21
- if 'choices' in data and len(data['choices']) > 0:
22
- command = data['choices'][0]['message']['content'].strip()
23
- return command
24
- elif 'error' in data:
25
- error_message = data['error']['message']
26
- return f'Ошибка: {error_message}'
27
- else:
28
- return f'Не удалось сгенерировать текст. {data}'
29
-
30
- iface = gr.Interface(fn=generate, inputs=[
31
- gr.Textbox(label="Запрос"),
32
- gr.Radio(show_label=True, label="Модель", interactive=True, choices=["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4"], value="gpt-3.5-turbo"),
33
- gr.Slider(show_label=True, label="Максимум токенов", minimum=100, maximum=15000, value=10000, step=1)
34
- ], outputs=gr.Textbox(label="Ответ"), title="EasyGPT")
35
- iface.launch()
 
2
  import requests
3
  import json
4
  import os
5
+ import time
6
 
7
  def generate(description, model, max_tokens):
8
  headers = {
 
16
  'model': model
17
  }
18
 
19
+ while True:
20
+ response = requests.post(os.getenv("BASE_URL"), headers=headers, json=payload)
21
+ data = json.loads(response.text)
22
 
23
+ if 'choices' in data and len(data['choices']) > 0:
24
+ command = data['choices'][0]['message']['content'].strip()
25
+ return command
26
+ elif 'error' in data:
27
+ error_message = data['error']['message']
28
+ print(f'Ошибка: {error_message}')
29
+ time.sleep(1)
30
+ else:
31
+ print(f'Не удалось сгенерировать текст. Повторная попытка...')
32
+ time.sleep(1)