Spaces:
Sleeping
Sleeping
File size: 1,364 Bytes
5768e97 c68c0dd 5768e97 640e460 5768e97 2dd0f0f 5768e97 |
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 |
import gradio as gr
from langchain_gigachat.chat_models import GigaChat
from dotenv import load_dotenv
import os
# Загрузка переменных из .env
load_dotenv()
giga = GigaChat(
credentials=os.getenv('GIGACHAT_KEY'),
verify_ssl_certs=False,
scope="GIGACHAT_API_CORP",
model='GigaChat-Max'
)
def generate_response(user_input):
"""Функция для генерации ответа от LLM"""
try:
response = giga.invoke(user_input)
return response.content # Предполагается, что ответ содержит ключ 'tex>
except Exception as e:
return f"Ошибка: {str(e)}"
# Интерфейс Gradio
def main():
interface = gr.Interface(
fn=generate_response,
inputs=gr.Textbox(label="Ваш запрос"),
outputs=gr.Textbox(label="Ответ от GigaChat"),
title="Генератор сообщений на основе GigaChat",
description="Введите ваш запрос, чтобы получить ответ от LLM от Сбера.",
allow_flagging="manual",
flagging_options=["Пометить"])
# Запуск сервера с публичным доступом
interface.launch(share=True) #server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__":
main()
|