Skip to content

Commit

Permalink
HF spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
HemanthSai7 committed Dec 14, 2023
0 parents commit 7a89bde
Show file tree
Hide file tree
Showing 43 changed files with 4,870 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
*.png
.png
frontend/images/architecture.png filter=lfs diff=lfs merge=lfs -text
StudybotAPI/assets/*.png filter=lfs diff=lfs merge=lfs -text
StudybotAPI/backend/data/History_1.pdf filter=lfs diff=lfs merge=lfs -text

16 changes: 16 additions & 0 deletions .github/workflows/checkfilesize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Check file size
on: # or directly `on: [push]` to run the action on every push on any branch
pull_request:
branches: [main]

# to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
sync-to-hub:
runs-on: ubuntu-latest
steps:
- name: Check large files
uses: ActionsDesk/[email protected]
with:
filesizelimit: 10485760 # this is 10MB so we can sync to HF Spaces
20 changes: 20 additions & 0 deletions .github/workflows/githubtohfsync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Sync to Hugging Face hub
on:
push:
branches: [main]

# to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
sync-to-hub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
lfs: true
- name: Push to hub
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: git push https://HemanthSai7:[email protected]/spaces/HemanthSai7/StudybotAPI main
137 changes: 137 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
marvin.toml
.marvin-history
marvin.egg-info

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
# dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# vector store
studybot/vectorstore/

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
cpcli-env/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.10.9

RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH

COPY --chown=user ./StudybotAPI $HOME/StudybotAPI

WORKDIR $HOME/StudybotAPI

RUN mkdir $HOME/.cache

RUN pip install --no-cache-dir --upgrade -r requirements.txt

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: StudybotAPI
emoji: 😻
colorFrom: gray
colorTo: blue
sdk: docker
pinned: false
---

# StudyBot x Streamlit

✨ Streamlit is an open-source app framework for Machine Learning and Data Science teams. Create beautiful data apps in hours, not weeks. All in pure Python. ✨

## Installation

```bash
pip install -r requirements.txt
```

## Start development server

> If you're using the default template, **remember to set the OpenAI API key** in `main.py`.
Run the following command:

```bash
cd StudybotAPI
uvicorn app:app --reload
```

Now go to [http://localhost:4000](http://localhost:4000) and start chatting with your bot! The bot will automatically reload when you change the code.

## Motive
When studying a theoretical subject, which has a lot of concepts, dates, important events etc. No matter how hard we try to momrize them, its hard to remember them all. So, I thought of making a bot which can help us in quick revision of the subject. For example, if we are studying history, and we forget the event of 1857 revolt, we can ask the bot like **"What happened in 1857?"** and it will tell us brief answer. This will help us in quick revision of the subject.

## How to use
Input the prompt in the text box and press enter. The bot will give you the answer. If you want to ask another question, just enter the question and the bot will try to answer.

## Screenshots
![image](StudybotAPI/assets/ss1.png)
![image](StudybotAPI/assets/ss2.png)
![image](StudybotAPI/assets/ss3.png)

## How it works
![image](StudybotAPI/assets/flowchart.png)

## Tech Stack
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)
![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi)
![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?style=for-the-badge&logo=html5&logoColor=white)
![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white)
![Langchain](https://img.shields.io/badge/langchain-%23E34F26.svg?style=for-the-badge&logo=langchains&logoColor=white)
![Huggingface](https://img.shields.io/badge/huggingface-%23E34F26.svg?style=for-the-badge&logo=huggingface&logoColor=white)
![Streamlit](https://img.shields.io/badge/streamlit-%23E34F26.svg?style=for-the-badge&logo=streamlit&logoColor=white)
![Docker](https://img.shields.io/badge/docker-%23E34F26.svg?style=for-the-badge&logo=docker&logoColor=white)
1 change: 1 addition & 0 deletions StudybotAPI/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from backend import app
40 changes: 40 additions & 0 deletions StudybotAPI/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import box
import yaml

from fastapi import FastAPI

from backend.ingestion import *

# from langchain.llms.huggingface_pipeline import HuggingFacePipeline


app = FastAPI(title="StudyBot API", version="0.1.0", description="API for StudyBot Project")

from backend import routes
# from backend.retriever import EmbeddingModel


try:
os.environ["TRANSFORMERS_CACHE"] = "/.cache"

with open("config.yml", "r", encoding="utf8") as ymlfile:
cfg = box.Box(yaml.safe_load(ymlfile))
app.state.emb = Embeddings(cfg)

# llm = HuggingFacePipeline(pipeline=EmbeddingModel._initialize_pipeline())
# llm = LlamaCpp(
# streaming=True,
# model_path="models/mistral-7b-instruct-v0.1.Q4_K_M.gguf",
# max_tokens=1500,
# temperature=0.4,
# top_p=1,
# gpu_layers=0,
# stream=True,
# verbose=False,
# n_threads=int(os.cpu_count() / 2),
# n_ctx=4096
# )

except Exception as e:
print(e)
27 changes: 27 additions & 0 deletions StudybotAPI/backend/core/ExceptionHandlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from backend import app
from .Exceptions import *

from fastapi.responses import JSONResponse
from fastapi.requests import Request
from fastapi import status

@app.exception_handler(ModelDeploymentException)
async def model_deploying_exception_handler(request: Request, exc: ModelDeploymentException):
return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content=repr(exc)
)

@app.exception_handler(InfoNotProvidedException)
async def info_not_provided_exception_handler(request: Request, exc: InfoNotProvidedException):
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content=repr(exc)
)

@app.exception_handler(DataNotUploadedException)
async def data_not_uploaded_exception_handler(request: Request, exc: DataNotUploadedException):
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content=repr(exc)
)
Loading

0 comments on commit 7a89bde

Please sign in to comment.