PolyakovK commited on
Commit
c4d61fc
·
1 Parent(s): 81d46d1
Files changed (1) hide show
  1. pages/recommendations.py +19 -20
pages/recommendations.py CHANGED
@@ -84,7 +84,7 @@ with col1:
84
  query = st.text_area('Введите запрос, чтобы получить рекомендации', f'{text}', height=95)
85
  with col2:
86
  number = st.number_input(
87
- "Сколько книг найти?", value=10
88
  )
89
  find_button = st.button('Найти', key='find_button', use_container_width=True)
90
 
@@ -99,25 +99,24 @@ if find_button and query:
99
  with col2:
100
  st.subheader(f"{row['title']}")
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
 
 
84
  query = st.text_area('Введите запрос, чтобы получить рекомендации', f'{text}', height=95)
85
  with col2:
86
  number = st.number_input(
87
+ "Сколько книг найти?", value=3
88
  )
89
  find_button = st.button('Найти', key='find_button', use_container_width=True)
90
 
 
99
  with col2:
100
  st.subheader(f"{row['title']}")
101
  st.write(f"**Автор:** {row['author']}")
102
+ tab1, tab2 = st.tabs(['Аннотация', 'Краткое содержание'])
103
+ with tab1:
104
+ st.write(row['annotation'])
 
105
  st.metric(label="Схожесть", value=f"{row['similarity_score']:.3f}")
106
+ st.write(f"**Ссылка:** {row['page_url']}")
107
+ with tab2:
108
+ template = "ты умеешь кратко в несколько предложений описывать содержание книги по ее названию"
109
+ system_message_prompt = SystemMessagePromptTemplate.from_template(template)
110
+ human_template = "Кратко опиши содержание книги под названием: {book_title}"
111
+ human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
112
+ chat_prompt = ChatPromptTemplate.from_messages(
113
+ [system_message_prompt, human_message_prompt]
114
+ )
115
+ formatted_prompt = chat_prompt.format_prompt(
116
+ book_title=row['title']
117
+ )
118
+ response = chat(formatted_prompt.to_messages())
119
+ st.write(response.content)
120
+ st.write("---")
121
  st.write("---")
122