PolyakovK commited on
Commit
81d46d1
·
1 Parent(s): 890cc34

final commit

Browse files
Files changed (2) hide show
  1. pages/recommendations.py +28 -1
  2. requirements.txt +2 -1
pages/recommendations.py CHANGED
@@ -6,6 +6,16 @@ from sentence_transformers import util
6
  from sentence_transformers import SentenceTransformer, util
7
  st.set_page_config(page_title="Custom Button Example", layout="wide")
8
 
 
 
 
 
 
 
 
 
 
 
9
  @st.cache_resource
10
  def load_model_all_mpnet():
11
  return SentenceTransformer('all-mpnet-base-v2')
@@ -52,6 +62,7 @@ search = st.radio(
52
  "Используем 'all-mpnet-base-v2'",
53
  "Используем 'msmarco-roberta-base-v3'",
54
  ],
 
55
  )
56
 
57
  def params(search):
@@ -90,7 +101,23 @@ if find_button and query:
90
  st.write(f"**Автор:** {row['author']}")
91
  st.write("---")
92
  st.write(row['annotation'])
93
- st.metric(label="Схожесть", value=f"{row['similarity_score']:.3f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  st.write(f"**Ссылка:** {row['page_url']}")
95
  st.write("---")
96
 
 
6
  from sentence_transformers import SentenceTransformer, util
7
  st.set_page_config(page_title="Custom Button Example", layout="wide")
8
 
9
+ from langchain.chat_models.gigachat import GigaChat
10
+ from langchain.prompts.chat import (
11
+ ChatPromptTemplate,
12
+ HumanMessagePromptTemplate,
13
+ SystemMessagePromptTemplate,
14
+ )
15
+ credentials = 'NDU5OTA0YzEtMWJkZi00OWE0LWEzZmEtNTZiNTg2MWI1ZjI3OjY5MGQ0NzRhLTExY2QtNDAzZi04ZGMwLWU5NDU1ZGQwMDY3Ng=='
16
+ chat = GigaChat(model='GigaChat', credentials=credentials, verify_ssl_certs=False)
17
+
18
+
19
  @st.cache_resource
20
  def load_model_all_mpnet():
21
  return SentenceTransformer('all-mpnet-base-v2')
 
62
  "Используем 'all-mpnet-base-v2'",
63
  "Используем 'msmarco-roberta-base-v3'",
64
  ],
65
+ horizontal=True,
66
  )
67
 
68
  def params(search):
 
101
  st.write(f"**Автор:** {row['author']}")
102
  st.write("---")
103
  st.write(row['annotation'])
104
+ col1, col2 = st.columns(2)
105
+ with col1:
106
+ st.metric(label="Схожесть", value=f"{row['similarity_score']:.3f}")
107
+ with col2:
108
+ with st.expander('Показать краткое содержание книги, используя GigaChat'):
109
+ template = "ты умеешь кратко в несколько предложений описывать содержание книги по ее названию"
110
+ system_message_prompt = SystemMessagePromptTemplate.from_template(template)
111
+ human_template = "Кратко опиши содержание книги под названием: {book_title}"
112
+ human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
113
+ chat_prompt = ChatPromptTemplate.from_messages(
114
+ [system_message_prompt, human_message_prompt]
115
+ )
116
+ formatted_prompt = chat_prompt.format_prompt(
117
+ book_title=row['title']
118
+ )
119
+ response = chat(formatted_prompt.to_messages())
120
+ st.write(response.content)
121
  st.write(f"**Ссылка:** {row['page_url']}")
122
  st.write("---")
123
 
requirements.txt CHANGED
@@ -2,4 +2,5 @@ beautifulsoup4==4.12.3
2
  pandas==2.2.2
3
  Requests==2.32.3
4
  streamlit==1.37.0
5
- sentence-transformers==3.0.1
 
 
2
  pandas==2.2.2
3
  Requests==2.32.3
4
  streamlit==1.37.0
5
+ sentence-transformers==3.0.1
6
+ gigachain-community==0.2.11