Upload transformer.py
Browse files- transformer.py +29 -0
transformer.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
|
7 |
+
@st.cache(allow_output_mutation=True)
|
8 |
+
def get_generator():
|
9 |
+
return pipeline("text-generation", model="sberbank-ai/rugpt3small_based_on_gpt2")
|
10 |
+
|
11 |
+
|
12 |
+
g = get_generator()
|
13 |
+
|
14 |
+
st.markdown("**Генератор смешных и не очень текстов**")
|
15 |
+
|
16 |
+
input_test = st.text_area("Введите начало текста:")
|
17 |
+
length = st.slider("Отрегeлируйте длину текста", min_value=50, max_value=200)
|
18 |
+
button = st.button("Сгенерировать!")
|
19 |
+
|
20 |
+
if button:
|
21 |
+
res = g(
|
22 |
+
input_test,
|
23 |
+
do_sample=True,
|
24 |
+
max_length=length,
|
25 |
+
top_k=50,
|
26 |
+
top_p=0.95,
|
27 |
+
num_returned_sequences=1,
|
28 |
+
)
|
29 |
+
st.markdown(res[0]["generated_text"])
|