Spaces:
Runtime error
Runtime error
File size: 1,802 Bytes
7f37183 a2de83d 7f37183 a2de83d 7f37183 a9d7e51 7f37183 a9751ec 9421b11 a9751ec 7f37183 66b99ed 7f37183 |
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 42 43 44 45 46 47 |
import torch
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import random
device = 'cpu'
def ans(question ):
description=''
category=''
seed = random.randint(1, 10000000)
print(f'Seed: {seed}')
torch.manual_seed(seed)
inp = tokenizer.encode(f'{"Категория: " + category + "" if category else ""}Вопрос: {question}Описание: {description}Ответ:',return_tensors="pt").to(device)
print('question',question)
gen = model.generate(inp, do_sample=True, top_p=0.9, temperature=0.86, max_new_tokens=100, repetition_penalty=1.2) #, stop_token="<eos>")
gen = tokenizer.decode(gen[0])
gen = gen[:gen.index('<eos>') if '<eos>' in gen else len(gen)]
gen = gen.split('Ответ:')[1]
return gen
# Download checkpoint:
checkpoint = "its5Q/rugpt3large_mailqa"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint)
model = model.eval()
# Gradio
title = "Ответы на главные вопросы жизни, вселенной и вообще"
description = "ruGPT large дообученная на датасете https://www.kaggle.com/datasets/atleast6characterss/otvetmailru-solved-questions "
article = "<p style='text-align: center'><a href='https://github.com/NeuralPushkin/MailRu_Q-A'>Github with fine-tuning ruGPT3large on QA</a></p> Cозданно при поддержке <p style='text-align: center'><a href='https://t.me/lovedeathtransformers'>Love Death Transformers</a></p>"
examples = [
["Как какать?"]
]
iface = gr.Interface(fn=ans, title=title, description=description, article=article, examples=examples, inputs="text", outputs="text")
if __name__ == "__main__":
iface.launch() |