MachineLearningReply/q-and-a-tool
0
1---2title: NLP Q&A Tool3emoji: ๐4colorFrom: indigo5colorTo: indigo6sdk: streamlit7sdk_version: 1.32.28app_file: app.py9pinned: false10---11 12# Document Insights - Extractive & Generative Methods using Haystack13 14This template [Streamlit](https://docs.streamlit.io/) app set up for15simple [Haystack search applications](https://docs.haystack.deepset.ai/docs/semantic_search). The template is ready to16do QA with **Retrievel Augmented Generation**, or **Ectractive QA**17 18Below you will also find instructions on how you19could [push this to Hugging Face Spaces ๐ค](#pushing-to-hugging-face-spaces-).20 21## Installation and Running22 23### Local development24 25To run the bare application which does _nothing_:26 271. Install requirements: `pip install -r requirements.txt`282. Run the streamlit app: `streamlit run app.py`29 30This will start up the app on `localhost:8501` where you will find a simple search bar. Before you start editing, you'll31notice that the app will only show you instructions on what to edit.32 33### Docker34 35To run the app in a Docker container:36 371. Build the Docker image: `docker build -t haystack-streamlit .`382. Run the Docker container: `docker run -p 8501:8501 haystack-streamlit` (make sure to bind any other ports you need)393. Open your browser and go to `http://localhost:8501`40 41### Repo structure42 43- `./utils`: This is where we have 3 files:44 - `config.py`: This file extracts all of the configuration settings from a `.env` file. For some config settings, it45 uses default values. An example of this is46 in [this demo project](https://github.com/TuanaCelik/should-i-follow/blob/main/utils/config.py).47 - `haystack.py`: Here you will find some functions already set up for you to start creating your Haystack search48 pipeline. It includes 2 main functions called `start_haystack()` which is what we use to create a pipeline and49 cache it, and `query()` which is the function called by `app.py` once a user query is received.50 - `ui.py`: Use this file for any UI and initial value setups.51- `app.py`: This is the main Streamlit application file that we will run. In its current state it has a simple search52 bar, a 'Run' button, and a response that you can highlight answers with.53- `requirements.txt`: This file includes the required libraries to run the Streamlit app.54- `document_qa_engine.py`: This file includes the QA pipeline with Haystack.55 56### What to edit?57 58There are default pipelines both in `start_haystack_extractive()` and `start_haystack_rag()`59 60- Change the pipelines to use the embedding models, extractive or generative models as you need.61- If using the `rag` task, change the `default_prompt_template` to use one of our available ones62 on [PromptHub](https://prompthub.deepset.ai) or create your own `PromptTemplate`63 64### Using local LLM models65 66To use the `local LLM` mode you can use [LM Studio](https://lmstudio.ai/) or [Ollama](https://ollama.com/).67For more info on how to run the app with a local LLM model please refer to the documentation of the tool you are using.68The `local_llm` mode expects an API available at `http://localhost:1234/v1`.69 70## Pushing to Hugging Face Spaces ๐ค71 72Below is an example GitHub action that will let you push your Streamlit app straight to the Hugging Face Hub as a Space.73 74A few things to pay attention to:75 761. Create a New Space on Hugging Face with the Streamlit SDK.772. Create a Hugging Face token on your HF account.783. Create a secret on your GitHub repo called `HF_TOKEN` and put your Hugging Face token here.794. If you're using DocumentStores or APIs that require some keys/tokens, make sure these are provided as a secret for80 your HF Space too!815. This readme is set up to tell HF spaces that it's using streamlit and that the app is running on `app.py`, make any82 changes to the frontmatter of this readme to display the title, emoji etc you desire.836. Create a file in `.github/workflows/hf_sync.yml`. Here's an example that you can change with your own information,84 and an [example workflow](https://github.com/TuanaCelik/should-i-follow/blob/main/.github/workflows/hf_sync.yml)85 working for the [Should I Follow demo](https://huggingface.co/spaces/deepset/should-i-follow)86 87```yaml88name: Sync to Hugging Face hub89on:90 push:91 branches: [ main ]92 93 # to run this workflow manually from the Actions tab94 workflow_dispatch:95 96jobs:97 sync-to-hub:98 runs-on: ubuntu-latest99 steps:100 - uses: actions/checkout@v2101 with:102 fetch-depth: 0103 lfs: true104 - name: Push to hub105 env:106 HF_TOKEN: ${{ secrets.HF_TOKEN }}107 run: git push --force https://{YOUR_HF_USERNAME}:$HF_TOKEN@{YOUR_HF_SPACE_REPO} main108```109 