Upload 10 files
Browse files- .idea/.gitignore +3 -0
- .idea/UniversityProjeck.iml +10 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- Russian_cuisine.db +3 -0
- datatest.py +88 -0
- faiss_index/index.faiss +0 -0
- faiss_index/index.pkl +3 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
.idea/UniversityProjeck.iml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$">
|
| 5 |
+
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
| 6 |
+
</content>
|
| 7 |
+
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
|
| 8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 9 |
+
</component>
|
| 10 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
| 4 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/UniversityProjeck.iml" filepath="$PROJECT_DIR$/.idea/UniversityProjeck.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
Russian_cuisine.db
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0abe5aadbf1cbc2a4b9b21c802b9027c0824e8fd257cb5f06142f1c02d8d7120
|
| 3 |
+
size 3223552
|
datatest.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import sqlite3
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
from langchain.chains.llm import LLMChain
|
| 6 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 7 |
+
from langchain_openai import OpenAIEmbeddings
|
| 8 |
+
from langchain_openai import OpenAI
|
| 9 |
+
from langchain_community.document_loaders import DataFrameLoader
|
| 10 |
+
from langchain_community.vectorstores import FAISS
|
| 11 |
+
from langchain.prompts import PromptTemplate
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Подключаемся к базе данных SQLite
|
| 15 |
+
connection = sqlite3.connect("C:\\Users\\lyuto\\OneDrive\\Рабочий стол\\UniversityProjeck\\Russian_cuisine.db")
|
| 16 |
+
|
| 17 |
+
# Запрашиваем данные из нужной таблицы
|
| 18 |
+
query = "SELECT * FROM 'Russian cuisine'"
|
| 19 |
+
|
| 20 |
+
# Загружаем данные в DataFrame
|
| 21 |
+
df = pd.read_sql_query(query, connection)
|
| 22 |
+
|
| 23 |
+
# Закрываем подключение к базе данных
|
| 24 |
+
connection.close()
|
| 25 |
+
|
| 26 |
+
df.head()
|
| 27 |
+
|
| 28 |
+
loader = DataFrameLoader(df, page_content_column='recipe_name')
|
| 29 |
+
documents = loader.load()
|
| 30 |
+
|
| 31 |
+
embeddings = OpenAIEmbeddings(openai_api_key="ваш OPENAI-ключ")
|
| 32 |
+
|
| 33 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 34 |
+
texts = text_splitter.split_documents(documents)
|
| 35 |
+
# создаем хранилище
|
| 36 |
+
db = FAISS.from_documents(texts, embeddings)
|
| 37 |
+
db.as_retriever()
|
| 38 |
+
|
| 39 |
+
prompt_template = """
|
| 40 |
+
Используя данные из рецепта, включающие алгоритм: {algorithm} и ингредиенты: {ingredients}, опишите подробно, как приготовить блюдо, чтобы читатель мог легко следовать вашему описанию.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
prompt = PromptTemplate(
|
| 44 |
+
template=prompt_template,
|
| 45 |
+
input_variables=["algorithm", "ingredients"]
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
max_tokens = 1500
|
| 49 |
+
|
| 50 |
+
# Инициализация модели OpenAI
|
| 51 |
+
llm = OpenAI(temperature=0, max_tokens=max_tokens, openai_api_key="ваш OPENAI-ключ")
|
| 52 |
+
|
| 53 |
+
# Создание LLMChain с prompt и llm
|
| 54 |
+
chain = LLMChain(prompt=prompt, llm=llm)
|
| 55 |
+
|
| 56 |
+
def clean_url(url):
|
| 57 |
+
url = "https:" + url
|
| 58 |
+
return url.replace('"', '')
|
| 59 |
+
def generate_recipe_description(query):
|
| 60 |
+
relevants = db.similarity_search(query)
|
| 61 |
+
if not relevants:
|
| 62 |
+
return "Не удалось найти информацию о данном рецепте."
|
| 63 |
+
|
| 64 |
+
# Извлечение метаданных (алгоритм и ингредиенты) из документа
|
| 65 |
+
recipe_data = relevants[0].metadata
|
| 66 |
+
algorithm = recipe_data.get('algorithm', '')
|
| 67 |
+
ingredients = recipe_data.get('ingredients', '')
|
| 68 |
+
photo_url = recipe_data.get('photo', None)
|
| 69 |
+
|
| 70 |
+
# Генерация подробного описания рецепта с использованием LLMChain
|
| 71 |
+
response = chain.run(algorithm=algorithm, ingredients=ingredients)
|
| 72 |
+
return response, photo_url
|
| 73 |
+
|
| 74 |
+
# Начало Streamlit-приложения
|
| 75 |
+
st.title("Ассистент по поиску рецептов ChefMate")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
query = st.text_input("Введите ваш запрос:")
|
| 79 |
+
|
| 80 |
+
if st.button("Получить рецепт"):
|
| 81 |
+
response, photo_url = generate_recipe_description(query)
|
| 82 |
+
avatar_url = "https://i.yapx.ru/XZyvC.png" # Укажите URL или путь к аватарке ассистента
|
| 83 |
+
st.image(avatar_url, width=50)
|
| 84 |
+
st.write("ChefMate:")
|
| 85 |
+
st.write(response)
|
| 86 |
+
if photo_url:
|
| 87 |
+
clean_url = clean_url(photo_url)
|
| 88 |
+
st.image(clean_url, width=400)
|
faiss_index/index.faiss
ADDED
|
Binary file (30.8 kB). View file
|
|
|
faiss_index/index.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84428a06324dfdb0e7c876116b5a905ab84f68ddea1712ab387078db047e3cd6
|
| 3 |
+
size 10396
|