Giter Club home page Giter Club logo

haystack-search-pipeline-streamlit's Introduction

title emoji colorFrom colorTo sdk sdk_version app_file pinned
Haystack Search Pipeline with Streamlit
๐Ÿ‘‘
indigo
indigo
streamlit
1.23.0
app.py
false

Template Streamlit App for Haystack Search Pipelines

This template Streamlit app set up for simple Haystack search applications which does nothing in this state.

See the 'How to use this template' instructions below to create a simple UI for your own Haystack search pipelines.

Below you will also find instructions on how you could push this to Hugging Face Spaces ๐Ÿค—.

Installation and Running

To run the bare application which does nothing:

  1. Install requirements: pip install -r requirements.txt
  2. Run the streamlit app: streamlit run app.py

This 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:

image

How to use this template

  1. Create a new repository from this template or simply open it in a codespace to start playing around ๐Ÿ’™
  2. Make sure your requirements.txt file includes the Haystack and Streamlit versions you would like to use.
  3. Complete the code to include your Haystack search pipeline and return the results.
  4. Make any UI edits you'd like to and share with the Haystack community ๐Ÿฅณ

Repo structure

  • ./utils: This is where we have 3 files:
    • config.py: This is empty in the current state. You may use this file if you'd like to make use of any secrets such as an OpenAI key, a token for an API and so on. An example of this is in this demo project.
    • 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.
    • ui.py: Use this file for any UI and initial value setups.
  • 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.

What to edit?

  1. Create your Haystack search pipeline in the start_haystack() function. For example and Extractive QA pipeline:
#choose a document store and write documents to it
document_store = InMemoryDocumentStore(use_bm25=True) 

retriever = BM25Retriever(document_store=document_store)
reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2", use_gpu=True)

pipe = Pipeline()
pipe.add_node(component=retriever, name="Retriever", inputs=['Query'])
pipe.add_node(component=reader, name="Reader", inputs=["Reader])
  1. Run your Haystack search pipeline in the query() function and return the results. E.g.
params = {"Retriever": {"top_k": 5}}
results = pipe.run(question, params=params)
return results["answers"]

Pushing to Hugging Face Spaces ๐Ÿค—

Below is an example GitHub action that will let you push your Streamlit app straight to the Hugging Face Hub as a Space.

A few things to pay attention to:

  1. Create a New Space on Hugging Face with the Streamlit SDK.
  2. Create a Hugging Face token on your HF account.
  3. Create a secret on your GitHub repo called HF_TOKEN and put your Hugging Face token here.
  4. 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!
  5. 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.
  6. 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 working for the Should I Follow demo
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@v2
        with:
          fetch-depth: 0
          lfs: true
      - name: Push to hub
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: git push --force https://{YOUR_HF_USERNAME}:$HF_TOKEN@{YOUR_HF_SPACE_REPO} main

haystack-search-pipeline-streamlit's People

Contributors

tuanacelik avatar bilgeyucel avatar anakin87 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.