CoolFace
Apppublic

MachineLearningReply/search_mlReply

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
README.md112 linesDownload Raw Back to root
1---2title: Document Insights - Extractive & Generative Methods3emoji: ๐Ÿ‘‘4colorFrom: indigo5colorTo: indigo6sdk: streamlit7sdk_version: 1.23.08app_file: app.py9pinned: false10---11 12# Template Streamlit App for Haystack Search Pipelines13 14This template [Streamlit](https://docs.streamlit.io/) app set up for simple [Haystack search applications](https://docs.haystack.deepset.ai/docs/semantic_search). The template is ready to do QA with **Retrievel Augmented Generation**, or **Ectractive QA**15 16See the ['How to use this template'](#how-to-use-this-template) instructions below to create a simple UI for your own Haystack search pipelines.17 18Below you will also find instructions on how you could [push this to Hugging Face Spaces ๐Ÿค—](#pushing-to-hugging-face-spaces-).19 20## Installation and Running21To run the bare application which does _nothing_:221. Install requirements: `pip install -r requirements.txt`232. Run the streamlit app: `streamlit run app.py`24 25This will start up the app on `localhost:8501` where you will find a simple search bar. Before you start editing, you'll notice that the app will only show you instructions on what to edit.26 27### Optional Configurations28 29You can set optional cofigurations to set the:30-  `--task` you want to start the app with: `rag` or `extractive` (default: rag)31-  `--store` you want to use: `inmemory`, `opensearch`, `weaviate` or `milvus` (default: inmemory)32-  `--name` you want to have for the app. (default: 'My Search App')33 34E.g.:35 36```bash37streamlit run app.py -- --store opensearch --task extractive --name 'My Opensearch Documentation Search'38```39 40In a `.env` file, include all the config settings that you would like to use based on:41- The DocumentStore of your choice42- The Extractive/Generative model of your choice43 44While the `/utils/config.py` will create default values for some configurations, others have to be set in the `.env` such as the `OPENAI_KEY`45 46Example `.env`47 48```49OPENAI_KEY=YOUR_KEY50EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L12-v251GENERATIVE_MODEL=text-davinci-00352```53 54 55## How to use this template561. Create a new repository from this template or simply open it in a codespace to start playing around ๐Ÿ’™572. Make sure your `requirements.txt` file includes the Haystack and Streamlit versions you would like to use.583. Change the code in `utils/haystack.py` if you would like a different pipeline.594. Create a `.env`file with all of your configuration settings.605. Make any UI edits you'd like to and [share with the Haystack community](https://haystack.deepeset.ai/community)616. Run the app as show in [installation and running](#installation-and-running)62 63### Repo structure64- `./utils`: This is where we have 3 files: 65    - `config.py`: This file extracts all of the configuration settings from a `.env` file. For some config settings, it uses default values. An example of this is in [this demo project](https://github.com/TuanaCelik/should-i-follow/blob/main/utils/config.py).66    - `haystack.py`: Here you will find some functions already set up for you to start creating your Haystack search pipeline. It includes 2 main functions called `start_haystack()` which is what we use to create a pipeline and cache it, and `query()` which is the function called by `app.py` once a user query is received.67    - `ui.py`: Use this file for any UI and initial value setups.68- `app.py`: This is the main Streamlit application file that we will run. In its current state it has a simple search bar, a 'Run' button, and a response that you can highlight answers with.69 70### What to edit?71There are default pipelines both in `start_haystack_extractive()` and `start_haystack_rag()`72 73- Change the pipelines to use the embedding models, extractive or generative models as you need.74- If using the `rag` task, change the `default_prompt_template` to use one of our available ones on [PromptHub](https://prompthub.deepset.ai) or create your own `PromptTemplate`75 76 77## Pushing to Hugging Face Spaces ๐Ÿค—78 79Below is an example GitHub action that will let you push your Streamlit app straight to the Hugging Face Hub as a Space.80 81A few things to pay attention to:82 831. Create a New Space on Hugging Face with the Streamlit SDK.842. Create a Hugging Face token on your HF account.853. Create a secret on your GitHub repo called `HF_TOKEN` and put your Hugging Face token here.864. If you're using DocumentStores or APIs that require some keys/tokens, make sure these are provided as a secret for your HF Space too!875. This readme is set up to tell HF spaces that it's using streamlit and that the app is running on `app.py`, make any changes to the frontmatter of this readme to display the title, emoji etc you desire.886. Create a file in `.github/workflows/hf_sync.yml`. Here's an example that you can change with your own information, and an [example workflow](https://github.com/TuanaCelik/should-i-follow/blob/main/.github/workflows/hf_sync.yml) working for the [Should I Follow demo](https://huggingface.co/spaces/deepset/should-i-follow)89 90```yaml91name: Sync to Hugging Face hub92on:93  push:94    branches: [main]95 96  # to run this workflow manually from the Actions tab97  workflow_dispatch:98 99jobs:100  sync-to-hub:101    runs-on: ubuntu-latest102    steps:103      - uses: actions/checkout@v2104        with:105          fetch-depth: 0106          lfs: true107      - name: Push to hub108        env:109          HF_TOKEN: ${{ secrets.HF_TOKEN }}110        run: git push --force https://{YOUR_HF_USERNAME}:$HF_TOKEN@{YOUR_HF_SPACE_REPO} main111```112