File size: 1,263 Bytes
9d2f85e
 
 
 
 
 
 
 
 
a1e48f7
9d2f85e
 
a1e48f7
9d2f85e
 
 
 
 
 
 
a1e48f7
 
 
 
 
 
 
 
9023bda
 
 
 
 
 
a1e48f7
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
# -*- coding: utf-8 -*-
"""FredAlpaca.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1W6DsQPLinVnuJKqhVASYpuVwuHhhtGLc
"""

import streamlit as st

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from transformers import GenerationConfig

model_name = "IlyaGusev/fred_t5_ru_turbo_alpaca"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to("cuda")
model.eval()

generation_config = GenerationConfig.from_pretrained(model_name)
st.title('Модель')
st.write('')
# Input text
text_in = st.text_input('Введите текст:')
# кнопка вывод результата
start = st.button('Start:')
if start:
    for sample in text_in:
        data = tokenizer(sample, return_tensors="pt")
        data = {k: v.to(model.device) for k, v in data.items()}
        output_ids = model.generate(**data,generation_config=generation_config)[0]
    #print(tokenizer.decode(data["input_ids"][0].tolist()))
    #print(tokenizer.decode(output_ids.tolist()))
    #print("====================")
    st.write("Результат:", tokenizer.decode(data["input_ids"][0].tolist()),tokenizer.decode(output_ids.tolist()))