Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
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)
|
|
|
|
|
|
|
|
|
|