Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from duckduckgo_search import DDGS | |
| # Инициализация DuckDuckGo Search | |
| ddgs = DDGS() | |
| # Функция для общения с ИИ | |
| def chat_with_ai(user_message): | |
| try: | |
| # Здесь вы можете заменить на нужную модель | |
| response = ddgs.chat(user_message, model='gpt-4o-mini') | |
| return response | |
| except Exception as e: | |
| return f'Ошибка: {str(e)}' | |
| # Создаем интерфейс Gradio | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Чат с ИИ через DuckDuckGo") | |
| user_input = gr.Textbox(label="Введите ваше сообщение...", placeholder="Введите ваше сообщение...", lines=2) | |
| output = gr.Textbox(label="Ответ ИИ:", interactive=False) | |
| submit_button = gr.Button("Отправить") | |
| submit_button.click(chat_with_ai, inputs=user_input, outputs=output) | |
| # Запускаем интерфейс | |
| demo.launch() | |