Spaces:
Runtime error
Runtime error
AlexWortega
commited on
Commit
·
7f37183
1
Parent(s):
1273676
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
device = 'cpu'
|
6 |
+
|
7 |
+
def ans(question, description='', category=''):
|
8 |
+
seed = random.randint(1, 10000000)
|
9 |
+
print(f'Seed: {seed}')
|
10 |
+
torch.manual_seed(seed)
|
11 |
+
|
12 |
+
inp = tokenizer.encode(f'{"Категория: " + category + "\n" if category else ""}Вопрос: {question}\nОписание: {description}\nОтвет:',return_tensors="pt").to(device)
|
13 |
+
print('question',question)
|
14 |
+
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>")
|
15 |
+
|
16 |
+
gen = tokenizer.decode(gen[0])
|
17 |
+
return gen[:gen.index('<eos>') if '<eos>' in gen else len(gen)]
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
# Download checkpoint:
|
26 |
+
checkpoint = "its5Q/rugpt3large_mailqa"
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
28 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint)
|
29 |
+
model = model.eval()
|
30 |
+
|
31 |
+
# Gradio
|
32 |
+
|
33 |
+
title = "Ответы на главные вопросы жизни, вселенной и вообще"
|
34 |
+
description = "ruGPT large дообученная на датасете https://www.kaggle.com/datasets/atleast6characterss/otvetmailru-solved-questions "
|
35 |
+
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>"
|
36 |
+
examples = [
|
37 |
+
["Как какать?"]
|
38 |
+
]
|
39 |
+
|
40 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
iface.launch()
|