Spaces:
Runtime error
Runtime error
File size: 1,228 Bytes
e92393d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
import requests
import json
import os
def gpt3_turbo(image=None, text=None):
# Замените 'YOUR_API_KEY' на ваш API ключ от OpenAI
api_key = os.getenv("API_KEY")
# Формируем данные для отправки запроса
data = {}
if image:
data['image'] = image
if text:
data['text'] = text
# Отправляем запрос на API GPT-3.5-turbo
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
endpoint = os.getenv("BASE_URL")
response = requests.post(endpoint, headers=headers, json={"prompt": data, "max_tokens": 50})
if response.status_code == 200:
result = response.json()
return result['choices'][0]['text']
else:
return "Ошибка при получении ответа от модели."
# Создаем интерфейс Gradio
iface = gr.Interface(
fn=gpt3_turbo,
inputs=["text", "text"],
outputs="text",
title="GPT",
description="Помощь ученикам, решение заданий",
interpretation="default"
)
# Запускаем интерфейс
iface.launch()
|