Commit
·
b0f0742
1
Parent(s):
023397e
Add project files including app.py, data, and documentation
Browse files- Dockerfile-2.txt +18 -0
- LICENSE.txt +21 -0
- README-2.md +25 -0
- app.py +52 -0
- combined_data.json +0 -0
Dockerfile-2.txt
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
USER user
|
5 |
+
|
6 |
+
ENV HOME=/home/user \
|
7 |
+
PATH=/home/user/.local/bin:$PATH \
|
8 |
+
UVICORN_WS_PROTOCOL=websockets
|
9 |
+
|
10 |
+
WORKDIR $HOME/app
|
11 |
+
|
12 |
+
COPY --chown=user . $HOME/app
|
13 |
+
|
14 |
+
RUN uv sync
|
15 |
+
|
16 |
+
EXPOSE 7860
|
17 |
+
|
18 |
+
CMD ["uv", "run", "chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
|
LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2025 Aneeta Xavier
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
README-2.md
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title : Pilates App Fine_Tuned
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
+
sdk: docker
|
7 |
+
app_file: app.py
|
8 |
+
pinned: false
|
9 |
+
license: mit
|
10 |
+
short_description: Tool to provide users reformer exercises
|
11 |
+
|
12 |
+
---
|
13 |
+
|
14 |
+
# Pilates Reformer RAG App Fine_Tuned
|
15 |
+
|
16 |
+
This Chainlit app answers questions using Pilates reformer videos and textbooks. All data is preloaded from `combined_data.json`.
|
17 |
+
|
18 |
+
## Run Locally
|
19 |
+
|
20 |
+
```bash
|
21 |
+
uv run chainlit run app.py
|
22 |
+
```
|
23 |
+
|
24 |
+
## Or Deploy to Hugging Face Space with Docker
|
25 |
+
Just upload this directory and you're done.
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from langchain_core.documents import Document
|
4 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
5 |
+
from langchain_community.vectorstores import FAISS
|
6 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
7 |
+
from langchain_openai import ChatOpenAI
|
8 |
+
from langchain.chains import RetrievalQA
|
9 |
+
import chainlit as cl
|
10 |
+
|
11 |
+
# === Load and prepare data ===
|
12 |
+
with open("combined_data.json", "r") as f:
|
13 |
+
raw_data = json.load(f)
|
14 |
+
|
15 |
+
all_docs = [
|
16 |
+
Document(page_content=entry["content"], metadata=entry["metadata"])
|
17 |
+
for entry in raw_data
|
18 |
+
]
|
19 |
+
|
20 |
+
# === Split documents into chunks ===
|
21 |
+
splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=50)
|
22 |
+
chunked_docs = splitter.split_documents(all_docs)
|
23 |
+
|
24 |
+
# === Use your fine-tuned Hugging Face embeddings ===
|
25 |
+
embedding_model = HuggingFaceEmbeddings(
|
26 |
+
model_name="AneetaXavier/reformer-pilates-embed-ft-49fc1835-9968-433d-9c45-1538ea91dcc9"
|
27 |
+
)
|
28 |
+
|
29 |
+
# === Set up FAISS vector store ===
|
30 |
+
vectorstore = FAISS.from_documents(chunked_docs, embedding_model)
|
31 |
+
retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
|
32 |
+
|
33 |
+
# === Load LLM ===
|
34 |
+
llm = ChatOpenAI(model_name="gpt-4.1-mini", temperature=0)
|
35 |
+
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=retriever)
|
36 |
+
|
37 |
+
# === Chainlit start event ===
|
38 |
+
@cl.on_chat_start
|
39 |
+
async def start():
|
40 |
+
await cl.Message("🤸 Ready! Ask me anything about Reformer Pilates.").send()
|
41 |
+
cl.user_session.set("qa_chain", qa_chain)
|
42 |
+
|
43 |
+
# === Chainlit message handler ===
|
44 |
+
@cl.on_message
|
45 |
+
async def handle_message(message: cl.Message):
|
46 |
+
chain = cl.user_session.get("qa_chain")
|
47 |
+
if chain:
|
48 |
+
try:
|
49 |
+
response = chain.run(message.content)
|
50 |
+
except Exception as e:
|
51 |
+
response = f"⚠️ Error: {str(e)}"
|
52 |
+
await cl.Message(response).send()
|
combined_data.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|