Spaces:
Sleeping
Sleeping
Update pages/✨third.py
Browse files- pages/✨third.py +69 -111
pages/✨third.py
CHANGED
@@ -1,114 +1,72 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import streamlit as st
|
4 |
-
import plotly.express as px
|
5 |
-
|
6 |
-
df = px.data.iris()
|
7 |
-
|
8 |
-
@st.cache_data
|
9 |
-
def get_img_as_base64(file):
|
10 |
-
with open(file, "rb") as f:
|
11 |
-
data = f.read()
|
12 |
-
return base64.b64encode(data).decode()
|
13 |
-
|
14 |
-
|
15 |
-
#img = get_img_as_base64("https://catherineasquithgallery.com/uploads/posts/2021-02/1612739741_65-p-goluboi-fon-tsifri-110.jpg")
|
16 |
-
|
17 |
-
page_bg_img = f"""
|
18 |
-
<style>
|
19 |
-
[data-testid="stAppViewContainer"] > .main {{
|
20 |
-
background-image: url("https://wallpapercave.com/wp/wp11966930.jpg");
|
21 |
-
background-size: 115%;
|
22 |
-
background-position: top left;
|
23 |
-
background-repeat: no-repeat;
|
24 |
-
background-attachment: local;
|
25 |
-
}}
|
26 |
-
|
27 |
-
[data-testid="stSidebar"] > div:first-child {{
|
28 |
-
background-image: url("https://ibb.co/ZBkdJRg");
|
29 |
-
background-size: 115%;
|
30 |
-
background-position: center;
|
31 |
-
background-repeat: no-repeat;
|
32 |
-
background-attachment: fixed;
|
33 |
-
}}
|
34 |
-
|
35 |
-
[data-testid="stHeader"] {{
|
36 |
-
background: rgba(0,0,0,0);
|
37 |
-
}}
|
38 |
-
|
39 |
-
[data-testid="stToolbar"] {{
|
40 |
-
right: 2rem;
|
41 |
-
}}
|
42 |
-
|
43 |
-
div.css-1n76uvr.e1tzin5v0 {{
|
44 |
-
background-color: rgba(238, 238, 238, 0.5);
|
45 |
-
border: 10px solid #EEEEEE;
|
46 |
-
padding: 5% 5% 5% 10%;
|
47 |
-
border-radius: 5px;
|
48 |
-
}}
|
49 |
-
|
50 |
-
</style>
|
51 |
-
"""
|
52 |
-
st.markdown(page_bg_img, unsafe_allow_html=True)
|
53 |
-
|
54 |
-
import tensorflow as tf
|
55 |
-
from tensorflow import keras
|
56 |
import numpy as np
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
#
|
64 |
-
|
65 |
-
#
|
66 |
-
#
|
67 |
-
|
68 |
-
|
69 |
-
#
|
70 |
-
#
|
71 |
-
#
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
#
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
#
|
101 |
-
|
102 |
-
|
103 |
-
#
|
104 |
-
|
105 |
-
|
106 |
-
#
|
107 |
-
|
108 |
-
|
109 |
-
#
|
110 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
################################################################################################
|
113 |
-
#st.markdown("<div style='text-align: center; font-size: 25px;'> ", unsafe_allow_html=True)
|
114 |
-
#st.markdown("<div style='text-align: center; font-size: 25px;'> ", unsafe_allow_html=True)
|
|
|
1 |
+
import transformers
|
2 |
import streamlit as st
|
3 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
import torch
|
7 |
+
|
8 |
+
st.title("""
|
9 |
+
History Mistery
|
10 |
+
""")
|
11 |
+
# image = Image.open('data-scins.jpeg')
|
12 |
+
|
13 |
+
# st.image(image, caption='Current mood')
|
14 |
+
# Добавление слайдера
|
15 |
+
temperature = st.slider("Градус дичи", 1.0, 20.0, 1.0)
|
16 |
+
# Загрузка модели и токенизатора
|
17 |
+
# model = GPT2LMHeadModel.from_pretrained('sberbank-ai/rugpt3small_based_on_gpt2')
|
18 |
+
# tokenizer = GPT2Tokenizer.from_pretrained('sberbank-ai/rugpt3small_based_on_gpt2')
|
19 |
+
# #Задаем класс модели (уже в streamlit/tg_bot)
|
20 |
+
model = GPT2LMHeadModel.from_pretrained(
|
21 |
+
'sberbank-ai/rugpt3small_based_on_gpt2',
|
22 |
+
output_attentions = False,
|
23 |
+
output_hidden_states = False,
|
24 |
+
)
|
25 |
+
tokenizer = GPT2Tokenizer.from_pretrained(
|
26 |
+
'sberbank-ai/rugpt3small_based_on_gpt2',
|
27 |
+
output_attentions = False,
|
28 |
+
output_hidden_states = False,
|
29 |
+
)
|
30 |
+
|
31 |
+
# # Вешаем сохраненные веса на нашу модель
|
32 |
+
model.load_state_dict(torch.load('model_history.pt',map_location=torch.device('cpu')))
|
33 |
+
# Функция для генерации текста
|
34 |
+
def generate_text(prompt):
|
35 |
+
# Преобразование входной строки в токены
|
36 |
+
input_ids = tokenizer.encode(prompt, return_tensors='pt')
|
37 |
+
|
38 |
+
# Генерация текста
|
39 |
+
output = model.generate(input_ids=input_ids, max_length=70, num_beams=5, do_sample=True,
|
40 |
+
temperature=1.0, top_k=50, top_p=0.6, no_repeat_ngram_size=3,
|
41 |
+
num_return_sequences=3)
|
42 |
+
|
43 |
+
# Декодирование сгенерированного текста
|
44 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
45 |
+
|
46 |
+
return generated_text
|
47 |
+
|
48 |
+
# Streamlit приложение
|
49 |
+
def main():
|
50 |
+
st.write("""
|
51 |
+
# GPT-3 генерация текста
|
52 |
+
""")
|
53 |
+
|
54 |
+
# Ввод строки пользователем
|
55 |
+
prompt = st.text_area("Какую фразу нужно продолжить:", value="В средние века на руси")
|
56 |
+
|
57 |
+
# # Генерация текста по введенной строке
|
58 |
+
# generated_text = generate_text(prompt)
|
59 |
+
# Создание кнопки "Сгенерировать"
|
60 |
+
generate_button = st.button("За работу!")
|
61 |
+
# Обработка события нажатия кнопки
|
62 |
+
if generate_button:
|
63 |
+
# Вывод сгенерированного текста
|
64 |
+
generated_text = generate_text(prompt)
|
65 |
+
st.subheader("Продолжение:")
|
66 |
+
st.write(generated_text)
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
if __name__ == "__main__":
|
71 |
+
main()
|
72 |
|
|
|
|
|
|