Spaces:
Runtime error
Runtime error
File size: 1,159 Bytes
99f514b 8ff7d89 99f514b 8ff7d89 |
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 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Задаем имя модели на Hugging Face
model_name = "AnatoliiPotapov/T-lite-instruct-0.1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Загрузка модели с параметрами для оптимизации работы на CPU
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", low_cpu_mem_usage=True)
# Функция для генерации ответа от модели
def generate_response(input_text):
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(inputs["input_ids"], max_length=50)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
# Настройка интерфейса Gradio
iface = gr.Interface(
fn=generate_response,
inputs="text",
outputs="text",
title="Telegram-like Chatbot",
description="Введите текст и получите ответ от модели"
)
# Запуск интерфейса с публичным доступом
iface.launch(share=True, server_port=7860) |