Spaces:
Sleeping
Sleeping
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() | |