Spaces:
Sleeping
Sleeping
File size: 934 Bytes
1875bec bd7f16d | 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 | import gradio as gr
import openai
# Функция для общения с GPT-4
def chat_with_gpt(api_key, user_input):
openai.api_key = api_key
try:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "user", "content": user_input}]
)
return response['choices'][0]['message']['content']
except Exception as e:
return str(e)
# Создаем интерфейс Gradio
with gr.Blocks() as demo:
gr.Markdown("# Chat with GPT-4")
api_key = gr.Textbox(label="Enter your OpenAI API Key", type="password")
user_input = gr.Textbox(label="You:", placeholder="Type your message here...")
output = gr.Textbox(label="GPT-4:", interactive=False)
submit_button = gr.Button("Send")
submit_button.click(chat_with_gpt, inputs=[api_key, user_input], outputs=output)
# Запускаем интерфейс
demo.launch()
|