Spaces:
Sleeping
Sleeping
File size: 1,271 Bytes
874475c a093bb1 874475c a093bb1 874475c a093bb1 874475c a093bb1 71de207 a093bb1 874475c a093bb1 874475c |
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 |
import gradio as gr
from g4f.client import Client
# Создаем экземпляр клиента
client = Client()
# Функция для общения с выбранной моделью
def chat_with_gpt(user_input, selected_model):
try:
response = client.chat.completions.create(
model=selected_model,
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 Models")
user_input = gr.Textbox(label="You:", placeholder="Type your message here...")
# Выпадающий список для выбора модели
model_selector = gr.Dropdown(
label="Select Model:",
choices=["gpt-4o", "gpt-4", "gpt-3.5-turbo", "gpt-4o-mini", "o1", "o1-mini"],
value="gpt-4o" # Значение по умолчанию
)
output = gr.Textbox(label="Response:", interactive=False)
submit_button = gr.Button("Send")
submit_button.click(chat_with_gpt, inputs=[user_input, model_selector], outputs=output)
# Запускаем интерфейс
demo.launch()
|