Rooni commited on
Commit
78b61f3
·
1 Parent(s): 548fc68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -6,6 +6,7 @@ import os
6
  def gpt3_turbo(image=None, text=None):
7
 
8
  api_key = os.getenv("API_KEY")
 
9
 
10
  # Формируем данные для отправки запроса
11
  data = {}
@@ -20,14 +21,14 @@ def gpt3_turbo(image=None, text=None):
20
  'Content-Type': 'application/json',
21
  'Authorization': f'Bearer {api_key}'
22
  }
23
- endpoint = os.getenv("BASE_URL")
24
- response = requests.post(endpoint, headers=headers, json={"prompt": data, "max_tokens": 100000, "model": 'gpt-3.5-turbo'})
25
-
26
- if response.status_code == 200:
27
  result = response.json()
28
  return result['choices'][0]['text']
29
- else:
30
- return "Ошибка при получении ответа от модели."
31
 
32
  # Создаем интерфейс Gradio
33
  iface = gr.Interface(
 
6
  def gpt3_turbo(image=None, text=None):
7
 
8
  api_key = os.getenv("API_KEY")
9
+ endpoint = os.getenv("BASE_URL")
10
 
11
  # Формируем данные для отправки запроса
12
  data = {}
 
21
  'Content-Type': 'application/json',
22
  'Authorization': f'Bearer {api_key}'
23
  }
24
+
25
+ try:
26
+ response = requests.post(endpoint, headers=headers, json={"prompt": data, "max_tokens": 100, "model": 'gpt-3.5-turbo'})
27
+ response.raise_for_status() # Проверка статуса ответа
28
  result = response.json()
29
  return result['choices'][0]['text']
30
+ except requests.RequestException as e:
31
+ return f"Ошибка при получении ответа от модели: {e}"
32
 
33
  # Создаем интерфейс Gradio
34
  iface = gr.Interface(